How to work with generic type

2

Hello! I'm starting in Delphi and I was creating a method to add margin to an object, but I needed it to be for any object. Example of the code you were working on.

Below is the code example I created to create the margin

procedure EditRectangleMargin(rtObjeto : TRectangle; bottom : double; left : double; right : double; top : double);
Begin
  //Seta a Magin do Objeto
   rtObjeto.Margins.Bottom := bottom;
   rtObjeto.Margins.Left := left;
   rtObjeto.Margins.Right := right;
   rtObjeto.Margins.Top := top;

But I would like to make a generic method that would serve both layout , label and so on. Can you create something like this in Delphi?

NOTE: I'm using firemonkey

    
asked by anonymous 26.09.2017 / 19:28

1 answer

0

The Margins property comes from TControl, so you can change its function to receive a TControl instead of a TRectangle.

procedure EditRectangleMargin(rtObjeto : TControl...

Since TLayout, TLabel, TRectangle, and many others descend from TControl. So you can send all the controls you have described using just one function.

    
26.09.2017 / 22:58