Solved

pointer

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 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

15 Experts available now in Live!

Get 1:1 Help Now