Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the equivalent of a static(class) field in Delphi?

I have a certain operation in a class that is very expensive. (on the order of about 8 seconds to fully run) So, now I've decided it should probably run at the beginning of the program during an "initialization" screen. I can't find anywhere in Delphi indicating that there is such a thing as a static field however.

What I basically need to do is load a list of records and keep them alive throughout the life of the program. What is the best way to do this in Delphi?

I would do this in C# quite simply:

class Foo{
  static List<...> Bar;
}

However in Delphi, I'm not seeing anything for creating a static field. All I see is the class keyword for creating static methods

like image 368
Earlz Avatar asked Jan 02 '12 15:01

Earlz


1 Answers

You can just use a global variable. Add it in the implementation section of a unit to make it local to that unit.

My Turbo Delphi supports class var x:integer;, but I'm pretty sure Delphi 7 doesn't.

like image 129
CodesInChaos Avatar answered Oct 13 '22 19:10

CodesInChaos