Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-08

FPC compiles malformed code

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

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 ----------------------

Regards,
- Graeme -

Reply by email

Vincent Snijders
to Graeme Geldenhuys
Graeme Geldenhuys wrote 49 lines
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

Reply by email

Graeme Geldenhuys
to Vincent Snijders
Show quoted text 6 lines
Maybe because pascal is insensitive to whitespace between tokens. You also can write: lData.Name:='Graeme'; and lData.Name := 'Graeme';
I understood that as: between the symbols etc... eg; := or = or ,
Never thought that would mean between a Class and a property/function.

Interesting but looks damn weird... :-)

Regards,
- Graeme -

Reply by email

Michael Müller
to Graeme Geldenhuys
Graeme Geldenhuys wrote 11 lines
> Maybe because pascal is insensitive to whitespace between tokens. > > You also can write: > lData.Name:='Graeme'; > and > lData.Name := 'Graeme'; I understood that as: between the symbols etc... eg; := or = or , Never thought that would mean between a Class and a property/function. Interesting but looks damn weird... :-)

And this seems to be the reason why the 'JCL Delphi Language Style Guide' claim in section '4.2.2 Blanks should not be used' (http:// homepages.borland.com/jedi/jcl/documents/styleguide.html#4.2.2): 'Before or after a .(dot) operator.'
So in general this seems to be permitted by Pascal/Delphi.

Regards

Michael

Reply by email