[Lazarus] Hook TComponent streaming system

Luiz Americo Pereira Camara luizmed at oi.com.br
Mon May 24 04:37:29 CEST 2010


Mattias Gaertner escreveu:
> On Sun, 23 May 2010 22:49:42 -0300
> Luiz Americo Pereira Camara <luizmed at oi.com.br> wrote:
>
>   
>> Michael Van Canneyt escreveu:
>>     
>>> On Sat, 22 May 2010, Luiz Americo Pereira Camara wrote:
>>>       
>>>> Mattias Gaertner escreveu:
>>>>         
>>>>> What do you want to achieve? Why do you think you have to set a 
>>>>> property after loading and before
>>>>> Loaded?
>>>>>           
>>>> Just for convenience.
>>>>
>>>> Currently i'm sending a custom message to notify the form that all 
>>>> properties (stored in lfm plus customized) are initialized so it can 
>>>> take the necessary actions:
>>>>
>>>> Form.Perform(CM_INIT, 0, 0);
>>>>
>>>> If i find such event/procedure i could get rid of the message 
>>>> sending/receiving.
>>>>
>>>> Not a big issue. I still can use OnShow, CreateWnd but it would not 
>>>> be as intuitive as using Loaded.
>>>>         
>>> What is wrong with overriding Loaded ? It is the last thing that is 
>>> called ?
>>>       
>> In fact i'd like to use an overrided Loaded in the created TForm. But it 
>> occurs to early:
>>
>> Form := TMyForm.Create;
>>       [..]//Streaming system
>>       TMyForm.Loaded; //> occurs before the customized properties are set
>> MySetPropertiesFunction(Form);//Set the desired properties. Too late to 
>> be recognized by TMyForm.Loaded
>>
>> I would need :
>>
>> Form := TMyForm.Create;
>>       [..]//Streaming system
>>       //hook streaming to call MySetPropertiesFunction(Form);//Set the 
>> desired properties.
>>       TMyForm.Loaded; //> i can assume that all properties are set
>>
>> By looking the TComponent/TReader code i could not figure how to do 
>> that, so if i did not missed something it seems is not possible.
>>     
>
> Why does the following not work for you?
>
> procedure TMyForm.Loaded; override;
> ...
> procedure TMyForm.Loaded; 
> begin
>   MySetPropertiesFunction(Self);
>   inherited Loaded;
> end;
>   
Because i don't know before hand what FormClass(TMyForm) is. Also 
FormClass (TMyForm) does not knows FormProperties

Here's the actual code (calls a generic TForm descendant):

The article: http://lazarusroad.blogspot.com/

function ShowForm(FormClass: TFormClass; Owner: TWinControl;  
FormProperties: array of const): TModalResult;
var
  Form: TForm;
begin
  Form := FormClass.Create(Owner);
  try
    SetObjectProperties(Form, FormProperties);
    Form.Perform(CM_INIT, 0, 0);
    Result := Form.ShowModal;
  finally
    Form.Destroy;
  end;
end;

Luiz




More information about the Lazarus mailing list