?
Solved

Regular procedure and method pointer

Posted on 2001-07-12
8
Medium Priority
?
747 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
[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
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
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!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 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