[fpc-pascal]class variable
Anton Tichawa
anton.tichawa at chello.at
Fri Apr 4 19:19:18 CEST 2003
Hello!
> The idea of a class variable is strange to me.
> Why not simply use a global variable ?
In fact it would be a global variable, but one that is bound to a class, also
in the sense of a namespace.
Consider, as an example, a class variable that holds the count of instances.
Something like (this is pseudo code - it will not work that simple):
type t_myclass_a = class
class var instance_count: integer;
end;
type t_my_class_b = class
class var instance_count: integer;
end;
procedure list_instances(aclass: tclass);
begin
writeln('the class ' + aclass.classname + ' has ' +
intstr(aclass.instance_count) + ' instances');
// i. e. accessing the proper global variable for
// the given class type
end;
Type checking and inheritance of class variables still would have to be
considered.
Anton.
----------
"Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte
Berechnungen einzuweben."
Doris Langley Moore: Ada, Countess of Lovelace (London 1977).
----------
Ing. Anton Tichawa
Volkertstrasse 19 / 20
A-1020 Wien
phone: +43 1 218 97 59
mobil: +43 664 52 07 907; currently n/a
email: anton.tichawa at chello.at
----------
More information about the fpc-pascal
mailing list