[Lazarus] constructor Create How is it work?

Mattias Gaertner nc-gaertnma at netcologne.de
Tue Mar 4 11:10:39 CET 2014


On Tue, 04 Mar 2014 11:50:33 +0200
FreeMan <freeman35 at delphiturkiye.com> wrote:

> Hello,
> constructor Create how is work ? In IDE not problem, but In application, 
> form created AOwner not nil, self created, FGrid created, but 
> Self.Parent is NILL ??? Self.left is 0 (not because its 10) all 
> Self.BoundsRect value is 0. Why? for test I added that code to in 
> @EditChange procedure (FGrid.Parent  := Self.Parent; this line and 
> later)  values is been correct, But in create not work properly.
> Has any one any idea?

A control is created like this:

ExLookUp1:=TExLookUp.Create(Form1);
with ExLookUp1 do begin
  Name:='ExLookUp1';
  Parent:=Form1;
  Left:=10;
  Top:=15;
  ...
end;

The order of setting properties is arbitrary. Your component should work
with any order. Keep in mind that properties might be set multiple
times.

> 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.BoundsRect.Bottom-4;
>    FGrid.Width := Self.BoundsRect.Right - Self.BoundsRect.Left;

Instead of fixed values you can define rules:

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

This way whenever the TExLookUp is resized the FGrid is resized as well.

See
http://wiki.lazarus.freepascal.org/Autosize_/_Layout

Mattias




More information about the Lazarus mailing list