Solved

pointer of function

Posted on 1998-04-06
1
156 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now