[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 =3D class
  public
    class procedure Hello; virtual;
  end;

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

  TAClass =3D 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 :=3D TB;
  SomeClass.Hello;
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freepascal.org/lists/fpc-pascal/attachments/20100113/e1a8=
3e69/attachment.htm


More information about the fpc-pascal mailing list