How to work with type Enerico

Asked

Viewed 87 times

2

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


Below is the example of the code I made 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 meets so much re-click when layout, label etc. You can create something like this in Delphi?

NOTE: I am using firemonkey

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 are descended from Tcontrol. So you can send all the controls you described using only one function.

  • But how do I implement this, I mean, do I have to import something? because only Tcontrolsize appears, but this one doesn’t have the properties;

  • You don’t have to import anything, Tcontrol exists for sure :p If you change your function header to this: Procedure Editrectanglemargin(rtObject : Tcontrol; bottom : double; left : double; right : double; top : double); Gives some error in the compiler?

  • It worked, because I was using a Unit without Form so I had to import FMX.Controls; Vlw guy.

  • Ah ok ;) You’re welcome

Browser other questions tagged

You are not signed in. Login or sign up in order to post.