OnActivate is triggered when you change focus of Forms of you application. If your app. has only one Form then it is triggered only one (after OnCreate).I'm not in front of code at the moment, so can't confirm for Lazarus, but I'm sure this isn't the case. Sure, if your application retains focus all the time, then OnActivate will only fire once. However, if you switch focus between different running applications, then when you switched back to your application, the OnActivate would fire again for that form.
BTW, if anybody wants to update the wiki - that would certainly help others looking for the same info...I'll run some tests on this tonight and do that. There's another minor change to the wiki I want to do tonight, so while I'm there anyway...
However, if you switch focus between different running applications, then when you switched back to your application, the OnActivate would fire again for that form.Not true here. I tried with one-form-app, switching between Laz. and this app. and also switching to other virtual desktop and back. OnActivate is triggered just once. I tried also with Delphi7 (uder Wine) and it is the same.
However, if you switch focus between different running applications, then when you switched back to your application, the OnActivate would fire again for that form.
Not true here. I tried with one-form-app, switching between Laz. and this app. and also switching to other virtual desktop and back. OnActivate is triggered just once. I tried also with Delphi7 (uder Wine) and it is the same.
No, I have just tested, TForm.OnActivate is triggered when focus is changed among forms within the application.
When the application receives focus, then TApplication.OnActivate is triggered.
Minor changes to the wiki made.
Changed wiki to say OnActivate happens after OnShow, not OnCreate
Added OnDeactivate
Added note on difference between Form.OnActivate/OnDeactivate and Application.OnActivate/OnDeactivate.
Thought about adding a comment about single form apps, but decided what's there actually covers all examples.
http://wiki.lazarus.freepascal.org/Event_order#Forms
Thought about adding a comment about single form apps, but decided what's there actually covers all examples.Then changed my mind, but put mentions in OnShow and OnDestory :-) Also, I finally noted the comment from @Howardpc below, liked it, stole it :-)
At the OnActivate stage controls instantiated in OnCreate are present and correct, and should have the minimum needed properties set (such as Parent) plus anything else OnCreate specified.
OnActivate signals that this form now has focus, so mouse/key events will start arriving.
OnCreate => OnShow => OnActivate => OnPaint => OnResize => OnPaint => ...But I get
OnCreate => OnResize => OnShow => OnPaint => (OnActivate =>) OnPaint => ...Removing the OnPaint event allows for OnActivate to be fully displayed.
Test code :I would not use ShowMessage in an event logging test program because in order to show the message the message dialog will get focus and may change the normal flow of events in Form1. It is much better to add a Memo to Form1 and call "Memo.Lines.Add(---message---)" in the event handlers rather than ShowMessage.
procedure TForm1.FormCreate(Sender: TObject);// 1 begin showmessage('create'); caption := 'create'; // not seen coz' form not displayed application.ProcessMessages; end; [...]
It is much better to add a Memo to Form1 and call "Memo.Lines.Add(---message---)" in the event handlers rather than ShowMessage.Thx for that idea, it's ok.