Mega Code Archive

 
Categories / Delphi / Ide Indy
 

Handling Global Application Object Events in Delphi

Title: Handling Global Application Object Events in Delphi The TApplicationEvents Delphi component wraps the global Application object available to you in all Delphi applications. When you drop a TApplicationEvents component to a (main) form, the unique Application object forwards all events to the TApplicationEvents object. Each event of the TApplicationEvents object is the same as the event with the same name on the Application object - all are visible in the ObjectInspector. Sometimes, not all :( For some events the Application object exposes, the TApplicationEvents does not expose the event in the Object Inspector. One such example are the OnModalBegin and OnModalEnd events in Delphi 7. The OnModalBegin and OnModalEnd are used in a trick to Dim Out the Main Form of an Application When Modal Form is Displayed Handling the "hidden" Application.OnSomething In case the Application object raises some event but the TApplicationEvents component does not display the event in the Object Inspector - you can attach an event handler to the event from code. Have a main form of the application. Create two procedures that have the TNotifyEvent signature. That's: procedure (Sender: TObject) of object. Attach the event handling procedure to the event. That's it :) interface private procedure FormModalBegin(Sender: TObject) ; procedure FormModalEnd(Sender: TObject) ; ... implementation //Handles (main) Form's OnCreate procedure TMainForm.FormCreate(Sender: TObject) ; begin Application.OnModalBegin := FormModalBegin; Application.OnModalEnd := FormModalEnd; end; procedure TMainForm.FormModalBegin(Sender: TObject) ; begin //do something on Modal Form Show end; procedure TMainForm.FormModalEnd(Sender: TObject) ; begin //do something on Modal Form Hide end; Make sure you explore the articles in the "Suggested Reading" box!