我正在使用这段代码
type
TSomeClass = class(TOBject)
private
class var InstanceCount : integer;
class var TotalInstanceCount : integer;
public
class function instances: integer;
class function totalInstances: integer;
constructor Create;
destructor Destroy;
end;
constructor TSomeClass.Create;
begin
inherited Create;
Inc(InstanceCount);
Inc(TotalInstanceCount);
end;
destructor TSomeClass.Destroy;
begin
Dec(InstanceCount);
inherited;
end;
class function TSomeClass.instances;
begin
Result := InstanceCount;
end;
class function TSomeClass.totalInstances;
begin
Result := TotalInstanceCount;
end;
我想创建一个实例计数器,并将一些类变量设置为私有。问题很简单,只需看这张图片:
如您所见,在红色框中,有我声明为私有的类变量。我不希望它们出现。我只想让公共类函数能够显示计数器。我该怎么做?
strict private
应该能解决你的问题。 - Jerry Dodge