Solved

Regular procedure and method pointer

Posted on 2001-07-12
8
744 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 73
delphi parse string to params 3 136
DBGrid or StringGrid ? 6 105
MS Access from Delphi 31 60
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 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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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