I wrote a D7 application to test the behavior of Application.OnActivate.
This is an important part:
procedure TMainForm.FormCreate (Sender: TObject); begin Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.FormCreate - Begin'); Application.OnActivate := AppActivate; Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.FormCreate - End'); end; procedure TMainForm.AppActivate (Sender: TObject); begin Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.AppActivate - Begin'); ShowWidthsHeights (Sender); Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.AppActivate - End'); end; procedure TMainForm.ShowWidthsHeights (Sender: TObject); begin Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.ShowWidthsHeights - Begin'); Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.ShowWidthsHeights - End'); end;
After starting the application, the contents of Memo1:
1 - MainForm.FormCreate - Start | 2 - MainForm.FormCreate - End
3 - MainForm.AppActivate - Start
4 - MainForm.ShowWidthsHeights - Start | 5 - MainForm.ShowWidthsHeights - End
6 - MainForm.AppActivate - End
It is right.
But if I then click on the shortcut in the taskbar, these 4 lines will be added to Memo1:
7 - MainForm.AppActivate - Start
8 - MainForm.ShowWidthsHeights - Start 9 - MainForm.ShowWidthsHeights - End
10 - MainForm.AppActivate - End
Why is D7 doing this?
My application is not activated, on the contrary, it is disabled!
To check if the Application.OnDeactivate event was fired, I added this event handler:
procedure TMainForm.AppDeactivate(Sender: TObject); begin Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.AppDeactivate - Begin'); Memo1.Lines.Add (IntToStr (Memo1.Lines.Count + 1) + ' - MainForm.AppDeactivate - End'); end;
and added this statement to TMainForm.FormCreate:
Application.OnDeactivate := AppDeactivate;
After starting the application, Memo1 contained the same 6 lines as in the original case, but clicking on the shortcut on the taskbar led to 8 additional lines in Memo1:
7 - MainForm.AppDeactivate - Begin 8 - MainForm.AppDeactivate - End 9 - MainForm.AppActivate - Begin 10 - MainForm.ShowWidthsHeights - Begin 11 - MainForm.ShowWidthsHeights - End 12 - MainForm.AppActivate - End 13 - MainForm.AppDeactivate - Begin 14 - MainForm.AppDeactivate - End
So, my application is deactivated, then activated, and then deactivated again!
This is pretty confusing!
AthenaAtDelphi
source share