当我使用TObjectDictionary时,TKey是对象,我的应用程序工作不正确.我有两个单元,它包含两个类.第一单元:
unit RubTerm;
interface
type
TRubTerm = Class(TObject)
private
FRubricName: String;
FTermName: String;
public
property RubricName: String read FRubricName;
property TermName: String read FTermName;
constructor Create(ARubricName, ATermName: String);
end;
implementation
constructor TRubTerm.Create(ARubricName, ATermName: String);
begin
Self.FRubricName := ARubricName;
Self.FTermName := ATermName;
end;
end;
Run Code Online (Sandbox Code Playgroud)
第二单元:
unit ClassificationMatrix;
interface
uses
System.Generics.Collections, System.Generics.Defaults, System.SysUtils, RubTerm;
type
TClassificationMatrix = class(TObject)
private
FTable: TObjectDictionary<TRubTerm, Integer>;
public
constructor Create;
procedure TClassificationMatrix.AddCount(ADocsCount: Integer; ARubName, ATermName: String);
function TClassificationMatrix.GetCount(ARubName, ATermName: String): Integer;
end;
implementation
constructor TClassificationMatrix.Create;
begin
FTable …Run Code Online (Sandbox Code Playgroud) 有一个类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;
Run Code Online (Sandbox Code Playgroud)
如何添加类字段(如C#中的静态字段)Persons:TDictionary(String,TPerson),其中键是SecondName,值是类TPerson的对象.
谢谢!
TListBox组件包含一组行(字符串).如何将此设置作为列表TList?下面的代码示例不会给出所需的结果.(Сode不编译)
MyList := TList<String>.Create(MyListBox);
MyList := TList<String>.Create(MyListBox.Items);
MyList := TList<String>.Create(MyListBox.Items.ToStringArray);
Run Code Online (Sandbox Code Playgroud)
是否可以在不使用循环的情况下执行此操作?谢谢!