Solved

Regular procedure and method pointer

Posted on 2001-07-12
8
743 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 100 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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