[fpc-pascal] FPC class syntax was extended to support delphi code

Anthony Walter sysrpl at gmail.com
Wed Jan 13 20:52:31 CET 2010


>
> Yup!
>
> Of course, there are pros and cons to all this. Our once simple,
> straightforward language is not littered with "convenience" features that
> are not necessary at all. For example, what is the big advantage of class
> methods over simple functions and procedures?
>

Class methods can be virtual and have access to other (perhpas protected)
class members of the class.

type
  TA = class
  public
    class procedure Hello; virtual;
  end;

  TB = class(TA)
  public
    class procedure Hello; override;
  end;

  TAClass = class of TA;

{ TA }

class procedure TA.Hello;
begin
  ShowMessage('Hello this is ' + ClassName); // see I can access ClassName
end;

{ TB }

class procedure TB.Hello;
begin
  inherited Hello;
  ShowMessage('A different message here');
end;

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
  SomeClass: TAClass;
begin
  SomeClass := TB;
  SomeClass.Hello;
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20100113/e1a83e69/attachment.html>


More information about the fpc-pascal mailing list