How to declare static variables in Delphi 2009?

I googled, I hung, I already saw other "duplicates" here, but none of them work in Delphi 2009, updated to update 4.

As in C #, I want to make a static variable in a string or as short as possible. In the end, it works like a global variable, but its sorting.

What is the shortest way to do this in delphi 2009?

EDIT

I followed some of your answers, but that didn't work.

Type of:

type TmyClass = class(TObject) var staticVar:integer; end; 

the code:

 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; 

I get the following errors:

 [DCC Error] Unit1.pas(31): E2096 Method identifier expected [DCC Error] Unit1.pas(32): E2096 Method identifier expected 
+6
static class delphi delphi-2009
source share
1 answer
 type TMyClass = class(TObject) private class var FX: Integer; public class property X: Integer read FX write FX; end; 

or shorter if you are not using a property

 type TMyClass = class(TObject) public class var X: Integer; end; 

to change . Pay attention to the class in the var class. You forgot this part.

+18
source share

All Articles