Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending library classes with own methods in Delphi pascal

I was wondering if there is a way to add custom method to already existing/included class component in Delphi Pascal.

I would like to use this to rotate StringGrid like this:

StringGridn.rotate(angle);

instead of:

rotate(StringGridn, angle);

Thanks for advice :)

like image 836
schullzroll Avatar asked Dec 14 '22 17:12

schullzroll


1 Answers

You can use helpers like in example below, see Class and Record Helpers (Delphi).

type  
  TStringGridHelper = class helper for TStringGrid
    procedure Rotate(Angle: Single);
  end;

procedure TStringGridHelper.Rotate(Angle: Single);
begin
  { your implementation }
  Rotate(Self, Angle);  
end;

and then just call

StringGridn.Rotate(Angle);
like image 164
Triber Avatar answered Mar 16 '23 00:03

Triber