Saturday, October 23, 2010

Difference between Method pointers and procedural pointers

While I was having some talk with my friends we ended up into a confusion as what exactly is the difference between the method pointers and procedureal pointers in Delphi and how it can be understood well. Well for a seasoned professional may be the answer to it is quiet easy but it took sometime before we really hit on the answer.

Method pointers are basically pointers to a method which is related to a class and as it is related to a class hence Delphi does pass on the 'Self' implicitly to the method so that the object can be referred to within the method pointed to by the method pointer. In case of a procedural pointer this 'Self' is what is missing and hence we can't have a procedural pointer refer to a class method.

This could be easily remembered the way a class method is defined -

MyClass.MyProcedure;

In this was we can see that we actually have MyClass which suggests that MyProcedure belongs to it. A normal procedure would be defined in this way -

MyProcedure;

suggesting that there is no class to which it belongs and hence no 'Self'.

No comments: