?
Solved

TTerminateProc - how to create/use procedure

Posted on 2002-06-17
4
Medium Priority
?
464 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 150 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

864 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