Link to home
Start Free TrialLog in
Avatar of Yas Da
Yas DaFlag for India

asked on

Tracking Delphi application close event.

I have 5 modules developed in Delphi. 

I want to have a global variable accessible to all modules, and this variable should track the application closure event. 

eg, FClose := True; when i close the application.

How can i do this, a code example should be great.

ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Yas Da

ASKER

I want to check something just before closing the apps, its the same functionality for all the app.
So i am thinking of a something generic.
Please suggest what is the best approach.
The generic approach is using the observer pattern and making all "modules" take part in int.

hi! it is very simple. Use main form event FormClose (or FormDestroy - but not recommend) and do something there.

Avatar of dfke
dfke

Hi,

You can also use Application.Terminate to trigger the same event.

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FClose := True;
  Application.Terminate;
end;

Open in new window


Cheers

It is obsolete to use Application.Terminate inside FormClose (and not recommended). 

When you get FormClose - application is going down anyway. 

This event is interesting because you can block closing app.