유니코드에서 PChar 타입은 PWideChar 타입이기 때문에 PChar 대신 PAnsiChar 타입으로 타입캐스팅해야 합니다.
result := CreateFileA(pAnsichar(fileName), c1, c2, nil, c3, 0, 0);
그리고 char 타입 역시 WideChar 타입이여서 집합이 표현할 수 있는 256개의 원소를 초과하기 때문에
경고가 발생합니다. 대신에 CharInSet 함수를 사용하세요.
CharInSet(fillChar, ['0'..'9'])
미모아 님이 쓰신 글 :
: 실은 델파이는 오늘 거의 처음봤습니다.-_-
: 소스컴파일이 필요해서 2010깔아서 컴파일을 하는데 아니나 다를까 경고,에러가 발생하네요
: 포럼을 뒤진결과 유니코드 관련 에러입니다.
:
: function CreateFileX(fileName: PWideChar; write, create: boolean) : dword;
: var c1, c2, c3 : dword;
: begin
: if write then begin
: c1 := GENERIC_READ or GENERIC_WRITE;
: c2 := 0;
: end else begin
: c1 := GENERIC_READ;
: c2 := FILE_SHARE_READ or FILE_SHARE_WRITE;
: end;
: if create then c3 := CREATE_ALWAYS
: else c3 := OPEN_EXISTING;
: if GetVersion and $80000000 = 0 then
: result := CreateFileW(fileName, c1, c2, nil, c3, 0, 0)
: else result := CreateFileA(pchar(string(wideString(fileName))), c1, c2, nil, c3, 0, 0);
: end;
:
: 컴파일러 에러는 else result := CreateFileA(pchar(string(wideString(fileName))), c1, c2, nil, c3, 0, 0);
: 이 부분에서
: [DCC Error] aModyUnit.pas(617): E2010 Incompatible types: 'Char' and 'AnsiChar'
: 이게 발생합니다. 코드기어 문서나 유니코드 관련 문서 봐도 이해 안되기는 매 한가지구요 ㅠ.ㅠ
:
:
: procedure _FillStr(var str: string; fillLen: integer; addLeft: boolean; fillChar: char);
: var s1 : string;
: begin
: if fillLen > 0 then begin
: SetLength(s1, fillLen);
: system.FillChar(pointer(s1)^, fillLen, byte(fillChar));
: if addLeft then begin
: if (fillChar in ['0'..'9']) and (str <> '') and (str[1] = '-') then
: str := '-' + s1 + RetDelete(str, 1, 1)
: else str := s1 + str;
: end else str := str + s1;
: end;
: end;
:
: 경고는 if (fillChar in ['0'..'9']) and (str <> '') and (str[1] = '-') then
: 이 부분에서
: [DCC Warning] aModyUnit.pas(278): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit.
:
: 그래서 [DCC Fatal Error] aFile.pas(8): F2063 Could not compile used unit 'aModyUnit.pas'
: 나와서 컴파일이 안되는데 저 문제가 해결되면 또 다른 에러가 발생하겠지만 돌파구를 알려주십시오.
:
: 스킨콤포넌트까지 사용하는데 스킨 콤포넌트는 2010에서 컴파일이 안되고
: MFC에서도 VS2008에서 와이드케릭터로 사람 머리아프게 만들더니 델파이도 같은 증상이 나와서 좌절입니다.
: 세상의 모든 프로그램이 기본적으로 유니코드를 지원하는날이 오길 바랍니다.
:
: 여러분 새해복많이 받으세요~