While porting some code from D2007 to XE2 I got a compiler error I can't understand. Please see the following sample:
procedure TForm1.FormPaint(Sender: TObject);
var
c: Char;
pc: PChar;
r: TRect;
begin
c := '1';
pc := @c;
r := Bounds(100, 100, 100, 100);
DrawText(Canvas.Handle, pc, 1, r, DT_SINGLELINE or DT_NOCLIP); //1
{$TYPEDADDRESS OFF}
DrawText(Canvas.Handle, @c, 1, r, DT_SINGLELINE or DT_NOCLIP); //2
{$TYPEDADDRESS ON}
DrawText(Canvas.Handle, @c, 1, r, DT_SINGLELINE or DT_NOCLIP); //3
DrawText(Canvas.Handle, PChar(@c), 1, r, DT_SINGLELINE or DT_NOCLIP); //4
end;
D2007 compiles that without a problem. The XE2 compiler rejects the line marked //3 with
[DCC Fehler] Unit1.pas(38): E2010 Inkompatible Typen: 'string' und 'Pointer'
I guess that is due to the newly added DrawText overloads accepting Delphi strings.
Can you explain that error? It's no big problem as I have a workaround (explicit casting), but I'm curious. Is the error still present in later Delphi versions?
Edit: I'm asking whether there is an error in the compiler, not for an explanation why it is there. It might well be that I overlooked a valid reason for the compiler to reject my code.
@cis treated in//3, or how the overload resolution is meant to work. So, if we cannot know how the overload resolution is meant to work, it's hard to judge whether this is a compiler bug or not. I might be wrong, but whenever I've looked at documentation for overload resolution I have found it to be incompletely described. - David Heffernancis aChar, so@cis aPChar, so choose the overload that explicitly takes aPChar. I don't really see how line//3is different from//1or//4regarding overload resolution.//2is different as@cis an untyped pointer there. - Uli Gerhardt