[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

TTerminateProc - how to create/use procedure

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 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