Iva*_*nov 6 delphi static class delphi-2009
我用谷歌搜索,我说,我已经看到了其他的"重复",但它们都没有在Delphi 2009中更新到更新4.
就像在C#中一样,我希望在线或尽可能短地创建一个静态变量.最后它就像一个全局变量,但它的排序.
在delphi 2009中最简单的方法是什么?
编辑
我按照你的一些答案,但它不起作用.
类型:
type
TmyClass = class(TObject)
var staticVar:integer;
end;
Run Code Online (Sandbox Code Playgroud)
码:
procedure TForm1.Button1Click(Sender: TObject);
var a:integer;
begin
TMyClass.staticVar := 5; // Line 31
a := TMyClass.staticVar; // Line 32
MessageBox(0,IntToStr(a),'',0);
end;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
[DCC Error] Unit1.pas(31): E2096 Method identifier expected
[DCC Error] Unit1.pas(32): E2096 Method identifier expected
Run Code Online (Sandbox Code Playgroud)
Lar*_*ens 18
type
TMyClass = class(TObject)
private
class var FX: Integer;
public
class property X: Integer read FX write FX;
end;
Run Code Online (Sandbox Code Playgroud)
如果您不使用财产,则更短或更短
type
TMyClass = class(TObject)
public
class var X: Integer;
end;
Run Code Online (Sandbox Code Playgroud)
编辑:请注意,类类变种.你忘记了这一部分.