Solved

TTerminateProc - how to create/use procedure

Posted on 2002-06-17
4
420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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