Stretchwickster
Programmer
Hi Everyone,
Does Delphi allow you to declare "class variables", that is variables which act as metadata for a class? For example, if you had a class called TPerson, would it be possible to have a class variable called PersonCount which is incremented in the TPerson constructor. PersonCount would not be instantiated with each instance of that class but would be associated with the class itself.
I know this is possible in Java and C++ (see "Static members" section of C++ Tutorial), as I vaguely remember doing it in the past. In Java, you can achieve it by declaring a variable as static e.g.
So is this possible in Delphi? If not, what other available option are there? My actual requirement is to have a class variable which is a collection storing information about object instances, but my simple example above illustrates the concept.
Clive![[infinity] [infinity] [infinity]](/data/assets/smilies/infinity.gif)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
Does Delphi allow you to declare "class variables", that is variables which act as metadata for a class? For example, if you had a class called TPerson, would it be possible to have a class variable called PersonCount which is incremented in the TPerson constructor. PersonCount would not be instantiated with each instance of that class but would be associated with the class itself.
I know this is possible in Java and C++ (see "Static members" section of C++ Tutorial), as I vaguely remember doing it in the past. In Java, you can achieve it by declaring a variable as static e.g.
Code:
static int PersonCount = 0;
So is this possible in Delphi? If not, what other available option are there? My actual requirement is to have a class variable which is a collection storing information about object instances, but my simple example above illustrates the concept.
Clive
![[infinity] [infinity] [infinity]](/data/assets/smilies/infinity.gif)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096