[fpc-devel] FPC compiles malformed code
Vincent Snijders
vsnijders at quicknet.nl
Thu Aug 24 09:48:29 CEST 2006
Graeme Geldenhuys wrote:
> Hi,
>
> Shouldn't FPC complain about the code below - I marked the lines with
> comments.
>
> lData.Name is typed as lData .Name
> the same for the function
> lDate.AsString is typed as lData .AsString.
>
> Notice the space before the dot...
>
>
> ----------------- CUT ---------------------
> program project1;
>
> {$mode objfpc}{$H+}
>
> uses
> Classes;
>
> type
> TMyClass = class(TObject)
> private
> FName: string;
> public
> property Name: string read FName write FName;
> function AsString: string;
> end;
>
> { TMyClass }
>
> function TMyClass.AsString: string;
> begin
> Writeln(Classname + '.Name: ' + FName);
> end;
>
> var
> lData: TMyClass;
> begin
> lData := TMyClass.Create;
> try
> lData .Name := 'Graeme'; // <== Why does this compile?
> lData .AsString; // <== Why does this compile?
> finally
> lData.Free;
> end;
> end.
>
> ---------------- END ----------------------
Maybe because pascal is insensitive to whitespace between tokens.
You also can write:
lData.Name:='Graeme';
and
lData.Name := 'Graeme';
Vincent
More information about the fpc-devel
mailing list