Solved

TTerminateProc - how to create/use procedure

Posted on 2002-06-17
4
403 Views
Last Modified: 2010-04-04
I found in the help that AddTerminateProc(TermProc:TTerminateProc) is used to add terminate procedure to your application. That means one has to create procedure of that type- I tried with
function DoCleanup:TTerminateProc
...
AddTerminateProc(DoCleanup)
...
but I got "incomaptible types" compiler message- How to declare and use this procedure. I need it because I want to:
1. Destroy some objects (exist through the whole life of application- arrays and TStringList)
2. Clear the "currently logged users" table if application crashes
Is that achievable with TTerminationProc?
0
Comment
Question by:bogiboy
  • 2
4 Comments
 
LVL 2

Expert Comment

by:Hagen040798
ID: 7084281
function DoCleanUp: Boolean;


AddTerminateProc(DoCleanUp);
0
 
LVL 1

Author Comment

by:bogiboy
ID: 7084517
I did that as well, before posting the question. Error was: "incompatible types- regular procedure and method pointer"....?
0
 
LVL 7

Accepted Solution

by:
Cynna earned 50 total points
ID: 7084576
bogiboy,

from SysUtils:

type
  TTerminateProc = function: Boolean;

So TTerminateProc is a *regular function*, not a method, without arguments, returns Boolean.



Copy/Paste this example:
----------------------------------

function MyExitFuction2: Boolean;
begin
   Result:=MessageDlg('Quit now?', mtConfirmation, [mbOK, mbCancel], 0) = mrOK;
end;

function MyExitFuction1: Boolean;
begin
   Result:=MessageDlg('*REALY* quit?', mtConfirmation, [mbOK, mbCancel], 0) = mrOK;
end;

...and place this in OnFormCreate:
--------------------------------------------

procedure TForm1.FormCreate(Sender: TObject);
begin
  AddTerminateProc(MyExitFuction1);
  AddTerminateProc(MyExitFuction2);
end;


See?


But, if you declare:

a) function TForm1.MyExitFuction2: Boolean;

instead of:

b) function MyExitFuction2: Boolean;

You'll get "incompatible types- regular procedure and
method pointer" because a) is actually method pointer,
and b) is regular procedure (aka TTerminateProc)

Also:

> .... Is that achievable with TTerminationProc?

Sure, that what it's for.


0
 
LVL 1

Author Comment

by:bogiboy
ID: 7090271
That's it! Thanks Cynna.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question