Delphi中的类字段(静态字段)
发布时间:2020-12-15 04:33:57 所属栏目:大数据 来源:网络整理
导读:有一个类TPerson.众所周知,FSecondName对每个对象都是唯一的. type TPerson = class(TObject) private FAge: Integer; FFirstName: String; FSecondName: String; public property Age: Integer read FAge; property FirstName: String read FFirstName; pro
有一个类TPerson.众所周知,FSecondName对每个对象都是唯一的.
type TPerson = class(TObject) private FAge: Integer; FFirstName: String; FSecondName: String; public property Age: Integer read FAge; property FirstName: String read FFirstName; property SecondName: String read FSecondName; constructor Create; end; 如何添加类字段(如C#中的静态字段)Persons:TDictionary(String,TPerson),其中键是SecondName,值是类TPerson的对象. 谢谢! 解决方法
您可以声明一个类变量:
type TMyClass = class private class var FMyClassVar: Integer; end; 显然,你可以使用你喜欢的任何类型的类变量. 类变量具有全局存储.所以变量有一个实例. Delphi类变量与C#静态字段直接相似. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |