Regular procedure and method pointer

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 ?
kogerAsked:
Who is Participating?
 
scrapdogConnect With a Mentor Commented:
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
 
EpsylonCommented:
To do that

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

should be

TCallBack = procedure (Position, Size: Integer; var Cancel: Boolean) of Object;
0
 
robert_marquardtCommented:
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
MadshiCommented:
Just to add another suggestion:

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

Regards, Madshi.
0
 
kretzschmarCommented:
madshi,
points are yours, i guess,
as i know you helped me with a similar q

meikl ;-)
0
 
scrapdogCommented:
In using MethodToProcedure:

Where does the method get the self pointer when it is called?  Is this magical?
0
 
scrapdogCommented:
Ahh, I am assuming that it dynamically creates a procedure like the one I have written above...
0
 
MadshiCommented:
Right, scrappy...  :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.