When porting code from D2007 to XE2, I received a compiler error that I cannot understand. See the following example:
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 this without a problem. The XE2 compiler rejects the line marked //3 with
[DCC Fehler] Unit1.pas (38): E2010 Inkompatible Typen: 'string' und 'Pointer'
I assume this is due to the recently added DrawText overloads accepting Delphi strings.
Can you explain this error? This is not a problem since I have a workaround (explicit casting), but I'm curious. Is the error still present in later versions of Delphi?
Edit: I ask if there is an error in the compiler, and not an explanation of why it is. It is possible that I overlooked the real reason the compiler refused my code.
delphi overload-resolution delphi-xe2
Uli gerhardt
source share