[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

pointer of function

Posted on 1998-04-06
1
Medium Priority
?
165 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 20 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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

649 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