Delphi static class methods are assignment compatible with plain old function pointers
Posted by jpluimers on 2013/04/24
So I won’t forget, as the [WayBack] static in different languages varies in meaning:
[WayBack] Static on class methods makes them assignment compatible with plain old function pointers.
Thanks Moritz Beutel for initially posting this.
–jeroen
via:
- [WayBack] oop – Does Delphi’s static keyword have any point in native-only code? – Stack Overflow
- [WayBack] static in different languages – Stack Overflow.
related:
- [Archive.is] Facebook – Delphi developer: static class methods
- [WayBack] Delphi 2007: Methods; Class Methods:
Like class methods, class static methods can be accessed without an object reference. Unlike ordinary class methods, class static methods have no Self parameter at all. They also cannot access any instance members. (They still have access to class fields, class properties, and class methods.) Also unlike class methods, class static methods cannot be declared virtual.
Methods are made class static by appending the word static to their declaration.
ObjectMethodology.com said
Good to know, thanks.
uligerhardt said
At last. :-) See [How compatible are static class methods and regular routine pointers?](http://stackoverflow.com/questions/6940171/how-compatible-are-static-class-methods-and-regular-routine-pointers)
jpluimers said
Thanks for providing that link.
A. Bouchez said
Of course!
I always saw static class methods as the new “global functions”.
And class variables as the new “global variables”.
To be used with care – unless your code may become not re-entrant any more – it may be the open door to make your code not thread-safe.
For instance, it may lead into impossibility to launch several class instances in parallel, or make your code much more difficult to test / mock / stub…
IMHO static class methods should be used with care, just as global functions are in pascal.
jpluimers said
Yeah, the “of course” is totally right. I had that very “duh” moment september last year with I found Moritz’ answer (:
And indeed: all static class stuff are replacements for global stuff with the benefit of an extra name in the scope so they won’t pollute the global scope.
Regular “global” criteria apply: use with care (: