Re:Delphi Guru - Correct Termination of a program (D1)
Quote
Michael Adkins wrote:
> Could someone please tell me the technically correct way of terminating a
> program's execution (using Delphi 1.0). I usually use the MainForm.Close
> method but if the application is currently busy (say in a loop) then the
> form doesn't close.
> I have tried many different methods all of which seem to have major
> shortcomings. (Application.Terminate; Halt; Exit; Abort etc etc). Ideally I
> need a method which still frees all memory allocated automatically but also
> breaks out of current execution.
> Can someone with a good knowledge of Delphi please help.
> Reply to newsgroup but cc: to madk...@tpgi.com.au is really appreciated.
> Thanks in advance.
> Cheers. Michael.
I usually make sure that the application is NEVER inside any
un-conditional loop unless it is absolutely necessary. But if you do
need it, try the following:
Place a global EXIT STATUS variable and initialize it to a value, let's
FALSE. No inside your loop (assuming Pascal) add an IF/EXIT statement
like:
for I := 1 to 90000 do
begin
// Do whatever is necessary.....
Application.ProcessMesssages;
if EXIT_STATUS = TRUE then
break;
end;
// Of course, you can put the condition checking along with the
WHILE loop expression
// if you using WHILE or UNTIL loop.
In your Form.Close event, you should set the EXIT_STATUS a value of
TRUE. This way, the FOR loop would naturally breaks and with necessary
agjustment, you should be able to terminate the application without even
making a Terminate, Halt or any calls.
Good Luck,