How to declare type for a class method in Delphi? -


how declare type class procedure, example

type   ttest = class     procedure proc1;     class procedure proc2;     class procedure proc3; static;   end;    tproc1 = procedure of object;   tproc2 = ???;   tproc3 = ???; 

tproc2 = procedure of object; 

a class method still has self pointer. it's class rather instance.

an interesting consequence of provides way implement event handlers without having instantiate object. instance, use class method of class that never instantiated way provide event handlers global application object.

tproc3 = procedure; 

a static class method has no self pointer. assignment compatible plain procedural type.

static class methods can used alternative globally scoped procedures. allow put such methods in namespace, of class, , avoid polluting global namespace.

take care when implementing static class methods not call virtual class methods. such calls bound statically @ compile time because lack of self pointer means dynamic polymorphic binding @ runtime not possible. rather disappointingly compiler fails warn of , need keep wits you.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -