Solved

TTerminateProc - how to create/use procedure

Posted on 2002-06-17
4
369 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
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…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now