我的理解是静态关键字是为了与.NET兼容而引入的(同时还有严格的)
@H_502_12@解决方法
class TExample class procedure First; class procedure Second; static;
第一和第二程序之间的差异是: –
>首先可以在后代课程中重写
>首先传递一个引用TExample类的隐式self参数.
类过程第二个不能被覆盖并且不传递任何参数,因此是.NET兼容的.因此,在原生代码中使用static关键字是否有任何意义,因为Delphi和&之间存在分歧.棱镜语法?
Static class methods have no hidden class reference argument.因此,它们与普通的旧函数指针兼容,因此可用于与Windows API和其他C API交互.例:
type TForm = class private class function NonStaticWndProc (wnd: HWND; Message: Cardinal; wParam: WPARAM; lParam: LPARAM): LRESULT; class function StaticWndProc (wnd: HWND; Message: Cardinal; wParam: WPARAM; lParam: LPARAM): LRESULT; static; procedure RegisterClass; end; procedure TForm.RegisterClass; type TWndProc = function (wnd: HWND; Message: Cardinal; wParam: WPARAM; lParam: LPARAM): LRESULT; var WP: TWndProc; WindowClass: WNDCLASS; begin //WP := NonStaticWndProc; // doesn't work WP := StaticWndProc; // works // ... TWndProc (WindowClass.lpfnWndProc) := WP; Windows.RegisterClass (WindowClass); end;