Solved

pointer

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

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

24 Experts available now in Live!

Get 1:1 Help Now