Delphi 8 Language Puzzles #1

Consider the following program for Delphi 8. If the dot is removed from the $DEFINE compiler directive, the code compiles, otherwise, it fails.

Why?

program Delphi8LanguageOddities;

{$APPTYPE CONSOLE}
{.$DEFINE VAROBJ}
uses SysUtils;

{$IF Defined(VAROBJ)}
procedure FillChar(var Obj: TObject; Size: Integer; Ch: WideChar);
begin
end;
{$ELSE}
procedure FillChar(Obj: TObject; Size: Integer; Ch: WideChar);
begin
end;
{$IFEND}

var
  A: DateTime;
begin
  A := Now;
  FillChar(A, SizeOf(A), #0);
end.

Published Mon, 31 May 2004 @ 7:00 AM by chuacw
Filed under:

Comments

# re: Delphi 8 Language Puzzles #1

Saturday, June 19, 2004 6:05 AM by chuacw

It's because variable "A" is of type DateTime and and the procedure FillChar is epecting a variable of type TObject. The other case compiles but I don't think that it will work because it will only be able to alter a local copy of Obj, it will not pass back the sender's Obj filled with zeros. Better would be to declare the procedure as FillChar(Obj: TObject; Size: Integer; Ch: WideChar) as Borland does in D2-D7.

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Enter the following code to ensure that your comment reaches the intended party:
Enter the numbers you see in the image: