Call global function from within Delphi class's method

JPv*_*rwe 2 delphi

Is it possible to call global methods from within a class where they are obscured by member functions of the same name?

I know in C++ you have the following syntax:

int var = 0;

void temp() {
    int var = 2;
    ::var = var;
} //Global var is set to 2
Run Code Online (Sandbox Code Playgroud)

Ale*_*exV 12

是的,您可以使用单位的名称而不是::

喜欢:

unit1.var := 2;
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅:http: //delphi.about.com/od/beginners/l/aa060899.htm

  • 这就是为什么我对 Delphi/Pascal 中“全局”一词的使用提出异议。即不是全局变量,而是单位变量。如果使用正确的术语,那么这些问题的答案将更加明显。即不是“我如何引用全局变量?”,而是“我如何引用单位变量?”。“使用”将单位符号带入范围的事实并不是在技术上没有这种概念的语言中误用“全局”含义的充分理由(而且官方帮助/文档也误用了该术语的事实也不是也请原谅)。 (2认同)

DiG*_*iGi 6

你可以试试

UnitName.VarName := 2
Run Code Online (Sandbox Code Playgroud)