?
Solved

Regular procedure and method pointer

Posted on 2001-07-12
8
Medium Priority
?
754 Views
Last Modified: 2008-03-17
I use an old unit, FastFileCopy to copy files.
The unit have declared a TCallBack
TCallBack = procedure (Position, Size: Integer; var Cancel: Boolean);

To use in this procedure call

procedure FastFileCopy(Const InFileName, OutFileName: String; CallBack: TCallBack);

How is it possible call the FastFileCopy procedure with a callback procedure located inanother object ?
0
Comment
Question by:koger
8 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6278983
To do that

TCallBack = procedure (Position, Size: Integer; var Cancel: Boolean);

should be

TCallBack = procedure (Position, Size: Integer; var Cancel: Boolean) of Object;
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6279459
I would not use such an method callback.
Adding a method callback to an otherwise function orinented API is not a good idea.
Either change the whole API to a class and make the callback an event or stay with the old API.
0
 
LVL 5

Accepted Solution

by:
scrapdog earned 300 total points
ID: 6279621
If you don't want to change the old unit, you can wrap your method in normal procedure.

procedure MyProcedure(Position, Size: Integer; var Cancel: Boolean);
begin
   MyObject.Method(Position, Size, Cancel);
end;

and then use MyProcedure as the callback function.

You could also use a class procedure if you desired, but you would still qualify the method with an instance of the class.

This would constitute poor programming practice, so if you have the option of changing the old unit, you are better off to go with Epsylon's suggestion.


0
Independent Software Vendors: 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!

 
LVL 20

Expert Comment

by:Madshi
ID: 6279649
Just to add another suggestion:

http://help.madshi.net/Data/MethodToProc.htm

Regards, Madshi.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6279670
madshi,
points are yours, i guess,
as i know you helped me with a similar q

meikl ;-)
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 6279680
In using MethodToProcedure:

Where does the method get the self pointer when it is called?  Is this magical?
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 6279683
Ahh, I am assuming that it dynamically creates a procedure like the one I have written above...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6279919
Right, scrappy...  :-)
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

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

862 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