Solved

pointer of function

Posted on 1998-04-06
1
159 Views
Last Modified: 2010-04-06
DELPHIer,

How can I get the pointer of a function and make use of it ?

For example,
There is a Button and some other controls in Main Form and there is a Click event in the Button object .
But, I also have three other functions called, FuncA, FuncB and FuncC inside the object of the Main Form.
So, how can I jump to FuncA or FuncB or FuncC when I click the Button through their pointers ?

thanks,
Andrew
0
Comment
Question by:andrewyu
1 Comment
 
LVL 1

Accepted Solution

by:
extreme earned 10 total points
ID: 1361312
That depends on the prototype of the functions. The prototype is how the functions are declared, for example, the function for the OnClick of the Button is of type TNotifyEvent that is declared as:

TNotifyEvent = procedure (Sender : TObject) of object;

That means that TNotifyEvent is a pointer to a procedure that received a sole parameter of type TObject, and that the procedure is inside an object.

So, supposing that your functions have the same prototype (receive a sole parameter of type TObject), then you can declare in some other object three field of type TnotifyEvent. Then you can do something like this:

Form2.FuncAAddress := Form1.FuncA;
Form2.FuncBAddress := Form1.FuncB ... the same for FuncC

then you simply can call the function pointer like this:

procedure TForm2.CallFuncA;
begin
  FuncAAddress (self);
end;

that will call FuncA of the Form1 passing as parameter the self pointer. Remember that is very important to declare the function pointer with the corresponding function prototype or Delphi will refuse to compile giving you an error.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IdTelnet1DataAvailable handler freezes the Application 4 74
Delphi 2 59
Tvertscrollbox like a whatsapp layout 5 26
enhance the following code 3 30
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

785 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