Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

pointer

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

972 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