I added class variables to the base class of the deep class hierarchy. This is an integer designed to count the number of instances created for each type of class. But I ran into a problem.
For example:
TBaseClass = class private class var fCreated: integer; public class function NewInstance: TObject; override; end; TDescendant = class(TBaseClass) end; ... class function TBaseClass.NewInstance: TObject; begin result := inherited NewInstance; inc(fCreated); end;
I suggested that I could use the var class to store the number of instances created for each class , but that doesn't seem to be the case.
The TBaseClass.fCreated
returns the same value as TDescendant.fCreated
, changing one with the inspector changes the other, so it behaves as if fCreated
is one global var.
I was expecting fCreated
be supported by class type, right? What am I missing?
source share