Search code examples
delphichardelphi-2007widechar

Incompatible char and widechar in Delphi


I have a strange problem.

I'm using Delphi 2007 and running it with the -r switch. On my computer everything works fine. When I transfer code to another computer I get an error:

Incompatible types char and widechar.

Maybe I should change some options.

Function that makes the problem:

function THcp.ConVertString(s: string): string;
Var i:integer;
    lstr:string;
begin
     lstr:=EmptyStr;
     for i := 1 to Length(s) do
     begin
           case s[i] of
             'Č': s[i]:='C';
             'č': s[i]:='c';
             'Ć': s[i]:='C';
             'ć': s[i]:='c';
             'Š': s[i]:='S';
             'š': s[i]:='s';
             'Đ': s[i]:='D';
             'đ': s[i]:='d';
             'Ž': s[i]:='Z';
             'ž': s[i]:='z';
           end;
           lstr:=lstr+s[i];
     end;
     Result:=lstr;
end;

Solution

  • This is my hypothesis. On the machine on which the code compiles, the non-ASCII characters in the code are all valid ANSI characters for that machine's locale. But the other machine uses a different locale under which some of those characters are not included in the >= 128 portion of the codepage. And hence those characters are promoted to WideChar and so of course are not compatible with AnsiChar.