[Lazarus] constructor Create How is it work?

FreeMan freeman35 at delphiturkiye.com
Wed Mar 5 12:35:20 CET 2014


DoDi Thank you very much, You explain much better then me :)
Main problem constructor not finished construction, I mean how to handle 
Self(TExLookUp) construction is finished? I have to wait, when 
self(TExLookUp) has created, and load self's properties loaded from, 
form resources (from .lfm) , then I can to use TExLookUp's properties, 
for child control, or some one else
I need similar a "TExLookUp.creatED" event, so I can now, class created 
and ready for use. This is not importend just my this component, other 
example,
was write previous message:

   TxItem = class(TCollectionItem)
   FName : string;
   property Name : string read Fname write Fname;
....
constructor Tx.Create(Collection: TCollection);
begin
   inherited Create(Collection);
.....
FName := 'XItem' + IntToStr(Index); --> FName is Item's name, 
TCollection.Index is always 0(zero). Collection added, so it has a index 
number from TCollectionItem, but TCollection not known this. I need 
unique FName, and "Index" property. I can get index if TCollection.CreatED;

@DoDi: "TExLookUp.OnCreate handler" how to add this? if add it my self, 
where to triggered or its just example
"AFAIK" what mean this word? english is not mine language, I'm using 
dictionary while writeing message.
Thank you

I hope I can translate my problem about create method


05-03-2014 08:29 tarihinde, Hans-Peter Diettrich yazdı:
FreeMan schrieb:
>> constructor TExLookUp.Create(AOwner: TComponent);
>> begin inherited Create(AOwner);
>>   Self.OnChange := @EditChange;
> set more Self properties here!
>
>>   FGrid := TRxDBGrid.Create(Self);
>>   FGrid.Parent := Self.Parent;
>>   FGrid.Left := Self.Left;
>>   FGrid.Top := Self.Heigh + 10;
>>   FGrid.Width := 150;
>>   FGrid.visible := False;
>> ...
>
> Please remember that you are in the TExLooUp constructor. Finish 
> initialization of this component, before assigning Self.whatever to 
> the FGrid.
>
> When the TExtLookUp is initialized from the form resource, you have to 
> wait until this has been done. In this case I'd move the FGrid related 
> part into the TExLookUp.OnCreate handler, which AFAIK is called 
> *after* the TExtLookUp has been created and fully initialized.
>
> Or put the code into ExtLookUp.SetParent, as Mattias suggests. But 
> this solution depends on the order, how the TExtLookUp properties are 
> initialized from the form resource. When Parent is set before Left, 
> Height etc., this solution doesn't work either.
>
> DoDi





More information about the Lazarus mailing list