2

I'm upgrading a very old (10+ years) application to the latest Delphi XE. There are a number of errors I keep getting like

Incompatible types: 'WideChar' and 'AnsiChar'

I have been just casting the char to the right type: ex. AWideChar = WideChar(fncReturnsChar);

Is this going to cause problems?

Wouter van Nifterick
  • 23,603
  • 7
  • 78
  • 122
Daisetsu
  • 4,846
  • 11
  • 50
  • 70
  • 1
    On XE you cannot get the error message that you report since `WideChar` and `Char` are one and the same. I think you need to show some more code. – David Heffernan Feb 14 '11 at 21:07
  • 2
    Also, have you read the various tutorials on how to switch to Unicode Delphi? In particular I believe there is a very useful white paper by Marco Cantu. – David Heffernan Feb 14 '11 at 21:10
  • @David The error I mentioned wasn't cut and paste, I meant to say 'AnsiChar' instead of 'Char'. Thanks to the link Mikael posted I've read the witepaper and understand now that WideChar=Char. I have to thank you for your help too, so here's an upvote. – Daisetsu Feb 14 '11 at 23:26

3 Answers3

6

There might be problems in there for you. Here is a white paper on Unicode in Delphi by Marco Cantù.

http://edn.embarcadero.com/article/38980

Mikael Eriksson
  • 136,425
  • 22
  • 210
  • 281
  • 2
    Wow, there's a LOT more to this than I originally thought. Thanks for the link, Marco always makes this stuff so easy to understand. – Daisetsu Feb 14 '11 at 23:24
  • @Daisetsu yes, it's easy to understand bitwise operations too, but having to understand the internals of a system in order to perform simple arithmetic on it is an indictment on the quality of the implementation. Technical crap like this has no place in a RAD IDE. It doesn't even belong in software, they should put it on the firmware like 3d-graphics functions are on graphics cards. It's the blind leading the blind again! – Sam Oct 24 '13 at 05:41
  • Bad Request (Invalid Hostname) – Fabrizio Sep 15 '20 at 07:28
2
var
    Initials: String[10];
    FullName: String;

begin

    Initials[1] := FullName[1]; // Error here after Delphi 2009

end;

The problem is that String[10] is the type of AnsiString in later Delphi versions. You are going to assign a Unicode character to an ANSI character in the above code.

The solution is a simple type cast:

Initials[1] := AnsiChar(FullName[1]);

Please refer the document recommended in Mikael Eriksson's answer. That is essential.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2
var
  C : Char;
  AC : AnsiChar;
begin
  AC := '1';
  // C := AC; Delphi does not know how to convert ANSI to Unicode without a codepage
  C := String(AC)[1]; // Any way we can do that by default ANSI decoder
end.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131