Board index » delphi » Assigning procedure to method pointers...??

Assigning procedure to method pointers...??

Hi!

I dynamically create some TComponents (TWSocket) in one of my programs.
When I try to assign a procedure to a method handler I get an error
that I can't assign a procedure to a method pointer....why!??

Thx...
Janus N. T?ndering

 

Re:Assigning procedure to method pointers...??


Sounds like you declared the procedure outside of a class.
Quote
Janus N. T?ndering wrote in message ...
>Hi!

>I dynamically create some TComponents (TWSocket) in one of my programs.
>When I try to assign a procedure to a method handler I get an error
>that I can't assign a procedure to a method pointer....why!??

>Thx...
>Janus N. T?ndering

Re:Assigning procedure to method pointers...??


In article <zNaH2.172$74....@news030.image.dk>, "Janus N. T?ndering"

Quote
<j...@nus.XpersonX.dk> writes:
>When I try to assign a procedure to a method handler I get an error
>that I can't assign a procedure to a method pointer....why!??

Because all instances of an object use the same method code (but different
property - data) then the method has to know which instance of the object is
calling the method. Delphi passes a hidden parameter for every method (in
addition to the ones declared in code) which is a pointer to the particular
instance which called the method. This hidden parameter is known by the name
Self and can be used in the method code if you wish.

Procedures do not have this hidden parameter (which methods _must_ have) so
procedures cannot be used an methods.

If you look at a methods type declaration it will say" procedure(param1 :
TType1 ; etc etc ) of object". The "of Object" tells Delphi to pass the
additional parameter for this type of procedure / function declaration.

Having said that, if you don't use Self in your procedure, you can code it as a
method of _any_ object and then specify it as the method you need.

Alan Lloyd
alangll...@aol.com

Other Threads