[Lazarus] constructor Create How is it work?

Mattias Gaertner nc-gaertnma at netcologne.de
Tue Mar 4 16:37:55 CET 2014


On Tue, 04 Mar 2014 17:19:23 +0200
FreeMan <freeman35 at delphiturkiye.com> wrote:

> ExLookUp1:=TExLookUp.Create(Form1); This is for manual creating, 

I showed you the corresponding code on how a designed component is
created, so you can see the order.


> I'm 
> talk about, I'm designing in IDE, 1-2 TExLookUp on form, and run my 
> application, TExLookUp is class(TCustomEditButton) so Edit and button is 
> shown on where I put on form, in designtime IDE.
> 
> constructor TExLookUp.Create(AOwner: TComponent);
> begin inherited Create(AOwner);
>    Self.OnChange := @EditChange;
>    FGrid := TRxDBGrid.Create(Self);
>    FGrid.Parent := Self.Parent;
>    FGrid.Left := Self.Left;
>    FGrid.Top := Self.Heigh + 10;
>    FGrid.Width := 150;
>    FGrid.visible := False;

I now see, that you are creating the Grid as neighbor of TExLookUp.
Then my prior mail was wrong and you can use the following rules to
position the FGrid below TExLookUp:

FGrid.AnchorParallel(akLeft,0,Self);
FGrid.AnchorParallel(akRight,0,Self);
FGrid.AnchorToNeighbour(akTop,0,Self);

Keep in mind that Parent is not yet set in the constructor.
You should override the method SetParent, so that each time
ExLookUp.Parent is changed the FGrid.Parent is changed as well.


>[...]
> > The order of setting properties is arbitrary. Your component should work
> > with any order.
> 
> Sorry, but I'm scared this answer, because nothing my under control

It means for example

Left:=3;
Width:=10;

or

Width:=10;
Left:=3;

or

Left:=30;
Width:=10;
Left:=3;

Writing a control that works in others people programs is more
complicated. You need to override more methods.

Mattias




More information about the Lazarus mailing list