1. Home
  2. Computing & Technology
  3. Delphi Programming

Handling Global Application Object Events in Delphi
What if TApplicationEvents does not expose OnSomething but knows about it?

By , About.com Guide

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!

Delphi tips navigator:
» Left Align Caption of a TSpeedButton Delphi button
« Dim Out the Main Form of an Application When Modal Form is Displayed

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2008 Tips
  7. Handling Global Application Object Events in Delphi

©2009 About.com, a part of The New York Times Company.

All rights reserved.