[lazarus] Calling a class method by pointer

Michael A. Hess mhess at miraclec.com
Sun May 16 23:33:00 EDT 1999


Shane Miller wrote:
> 
> Look in the  TForms or TControls source.  There are examples on this.
> I say....
> if Assigned(FOnClick) then FOnClick(self);
> 
> FOnClick is set by saying FOnClick := @SomeProcedure
> 
> SomeProcedure is defined as
> Procedure SomeProcedure(Sender : TObject);
> 
> Shane

I guess you didn't understand my email. It isn't that I don't know how
to do it, I do. The problem is that the correct procedure is called but
the application will abort with an Access Violation when it attempts to
return from the procedure. If the procedure isn't part of a class in
other words a class method it can be called and returns without any
problem. In your examples you are calling a given class method from
inside the class itself. You are just using a pointer of the same name
and type.

Yes if you look at my example it to is trying to call it from inside the
class but the way I want to implement it is by calling it from outside
the class. I showed the example in the class to indicate that it doesn't
work this way either. It gives the Access Violation. Also in my example
I am casting a regular pointer to a new Type TProcedure where as yours
was declared as the TNotifyEvent to begin with.

So why does that make it different? That is what I was asking!  :-\

-- 
==== Programming my first best destiny! ====

Michael A. Hess      Miracle Concepts, Inc.
mhess at miraclec.com   http://www.miraclec.com






More information about the Lazarus mailing list