Skip to content

Instantly share code, notes, and snippets.

@frantic
Created November 20, 2010 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frantic/4e23b7fa71717aa6f052 to your computer and use it in GitHub Desktop.
Save frantic/4e23b7fa71717aa6f052 to your computer and use it in GitHub Desktop.
Class helpers inheritance
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
TThirdPartyHelper = class helper for TObject
public
procedure SayHello; // virtual;
end;
TMyHelper = class helper (TThirdPartyHelper) for TObject
public
procedure SayHello; // override;
procedure SayHi;
end;
{ TThirdPartyHelper }
procedure TThirdPartyHelper.SayHello;
begin
Writeln('Hello, world!');
end;
{ TMyHelper }
procedure TMyHelper.SayHello;
begin
inherited SayHello; // does work if you dont specify method name explicitly
Writeln('My hello!');
end;
procedure TMyHelper.SayHi;
begin
Writeln('Hi all!');
end;
var
X: TObject;
begin
X := TObject.Create;
try
X.SayHello;
X.SayHi;
finally
FreeAndNil(X);
end;
Readln;
end.
@frantic
Copy link
Author

frantic commented Nov 20, 2010

Outputs:
Hello, world!
My hello!
Hi all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment