delphi一个类中如何调用非该类的重名过程
procedure gg; begin Application.MessageBox('马迪 ', '晕死ua', MB_OK + MB_ICONINFORMATION); end; procedure Test.gg; begin Application.MessageBox('我操', '麻痹', MB_OK + MB_ICONINFORMATION); end; procedure Test.KK; begin gg; end;
我想让TEST.KK调用全局的静态过程 !要怎么写呢
type Test2 = class(TObject) class procedure gg; end; class procedure Test2.gg; begin Application.MessageBox('马迪 ', '晕死ua', MB_OK + MB_ICONINFORMATION); end; procedure Test.gg; begin Application.MessageBox('我操', '麻痹', MB_OK + MB_ICONINFORMATION) end; procedure Test.KK; begin test2.gg; end;
在普通方法声明和实现前冠以class关键字
type
Test2 = class(TObject)
class procedure gg;
end;
class procedure Test2.gg;
begin
Application.MessageBox('马迪 ', '晕死ua', MB_OK + MB_ICONINFORMATION);
end;
........
Test2.gg; //调用
//如果不想用class过程,也可以给过程起个别名 type TPGG = procedure(); end; procedure gg; begin Application.MessageBox('马迪 ', '晕死ua', MB_OK + MB_ICONINFORMATION); end; var pg:TPGG = gg; procedure TForm1.gg; begin Application.MessageBox('我操', '麻痹', MB_OK + MB_ICONINFORMATION); end; procedure TForm1.KK; begin pg; end; // 或者用类似名字空间的方式 unit Unit2; interfaceuses Forms; procedure gg(); implementationprocedure gg(); begin Application.MessageBox('sdfdsf','fdsfs'); //; end; end. .... unit Unit1; type test = class; gg; end; uses unit_1; procedure test.gg; begin Unit2.gg; // 显示给出Unit2 end;