[Lazarus] Hook TComponent streaming system

Luiz Americo Pereira Camara luizmed at oi.com.br
Mon May 24 18:38:06 CEST 2010


Mattias Gaertner escreveu:
> On Mon, 24 May 2010 07:01:21 -0300
> Luiz Americo Pereira Camara <luizmed at oi.com.br> wrote:
>
>   
>> Mattias Gaertner escreveu:
>>     
>>> On Sun, 23 May 2010 23:37:29 -0300
>>> Luiz Americo Pereira Camara <luizmed at oi.com.br> wrote:
>>>
>>>   
>>>       
>>>> Mattias Gaertner escreveu:
>>>> [...]
>>>> Here's the actual code (calls a generic TForm descendant):
>>>>
>>>> The article: http://lazarusroad.blogspot.com/
>>>>     
>>>>         
>>> The article does not explain why the properties must be set before
>>> calling Loaded.
>>>  
>>>   
>>>       
>> If
>> procedure TMyForm.Loaded;
>> begin
>>   inherited;
>>   if MyBool then
>>      DoAction;
>> end;
>>     
>
> Is this correct:
> One of your forms has a design bug, which you can not fix (for
> whatever reason), so you need a workaround.
>   

It's not intended at a specific case. I just created a way to call 
generic TForm descendants with generic properties, basically to avoid 
boilerplate code. It's is already working fine, i'm just trying to avoid 
an extra notification (the CM_INIT message). I can also use OnShow or 
CreateWnd. An example:

TEditMyObjectForm = class(TForm)
 [..] //Controls created at design time (stored in the lfm)
published
  //customized property
  property MyObject: TMyObject;
end;

To show that form setting the property MyObject i would do:

Form := TEditMyObjectForm.Create(nil);
try
  Form.MyObject := ObjectX;
  Result :=  Form.ShowModal = mrOk;
finally
  Form.Destroy;
end;


With my function i do:

Result := ShowForm(TEditMyObjectForm, nil, ['MyObject', ObjectX]) = mrOk;

> I see several solutions:
> - Patch and compile your own special version of TReader or LCL.
> - modify the lfm at runtime
> - modify the VMT at runtime and override Loaded
>   

Wow. Not necessary too much. I can live with a message handler ;-)

Luiz




More information about the Lazarus mailing list