Solved

pointer

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

How can I get the pointer of a function ?
Why I cannot access the data when the pointer is nil ?

Andrew
0
Comment
Question by:andrewyu
1 Comment
 
LVL 1

Accepted Solution

by:
extreme earned 10 total points
ID: 1361313
I presume you want to get the address of a function. Well, to get the address depends on the context where you are working. For example, if you want to assign the address of a function to a variable to call the function later using this var you should write code like this:

var
  FOnClick : TNotifyEvent;
begin
  FOnClick := Form1.Button1Click;

  if assigned (FOnClick)
    then FOnClick (xx);


that code get the address of the button1Click method and assign it to the var FOnClick, later you can use the var to call the function, but always you have to check if the value is diferent of nil using assigned. If you don't do so, trying to do something like:

if FOnClick <> nil
   then xxxx....

Delphi tried to call the function because it's in the left of an expression, when the function is in the right in an assignment statement then delphi get the address. That's why you cannot compare directly with nil the function pointer.

When a pointer is nil, is because the pointer don't points to anything, so you cannot reference the pointer otherwise you will get an access violation.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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…

776 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