How compatible are static class methods and regular routine pointers?

会有一股神秘感。 提交于 2019-12-05 22:09:38

There is no difference on binary level between static class function and ordinary function with the same arguments&result type - they are binary compatible, so your example is OK. Of course they are different types for the compiler, so you need Addr() or @ to compile your example.

Addr() is equivalent to the @ operator except that it is unaffected by the $T compiler directive.If you switch type check on your example will not compile:

{$T+}
begin
  CallIt(@TMyClass.StaticMethod);
  Readln;
end.

[Pascal Error] Project10.dpr(28): E2010 Incompatible types: 'TFunc' and 'Pointer'

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!