Solved

pointer of function

Posted on 1998-04-06
1
162 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
[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
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

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!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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