[Lazarus] Doing work in FormActivate

svaa svaa at ciberpiula.net
Wed Jan 14 10:21:55 CET 2009


Gabor Boros escribió:
> Hi,
>
> A simple test case:
>
> procedure TForm1.FormActivate(Sender: TObject);
> begin
>    Caption:=FormatDateTime('hh:mm:ss',Now);
> end;
>
> With Delphi the form's caption show the first activation time and with 
> Lazarus the caption changed when switch to other application and switch 
> back etc.. I don't say Delphi is correct but after working many years 
> with Delphi this thing is strange for me.
>
>   
I think he is right, if you switch of application in delphi, the 
onActivate event is not fired.

Besides the first activate, the onActive event is fired when you show  
modal forms that are hidden, it's fired also when stayOnTop and mdiChild 
forms are unfocused and get the focus. But not when the switch of 
application (unless you bring to front a form when the application gets 
the focus again).

The onShow only works, besides the first activate, when you hide and 
show a form.

However, I have always found this behavior stranger or at least 
incomplete. I have always missed a "onFirstActivate" event. Most times I 
use onFormActivate to init some controls depending upon variables set by 
the caller between the create and the activate, most of this action must 
be done just one time, not each time it loses and gets the focus again. 
The problem is so usual that I have even made standard the use of a 
variable fFirstActivate that can be found is in many of my forms.

It wouldn't be a bad idea to add onFirstActivate although it breaks 
delphi compatibility a little.

Santiago A.




More information about the Lazarus mailing list