小编And*_*rew的帖子

在TObjectDictionary中使用对象作为键

当我使用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)

delphi delphi-xe2

6
推荐指数
2
解决办法
3205
查看次数

Delphi中的类字段(静态字段)

有一个类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的对象.

谢谢!

delphi static tdictionary

6
推荐指数
1
解决办法
3157
查看次数

将ListBox中的字符串转换为List <String>

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)

是否可以在不使用循环的情况下执行此操作?谢谢!

delphi tlist tlistbox

2
推荐指数
1
解决办法
1712
查看次数

标签 统计

delphi ×3

delphi-xe2 ×1

static ×1

tdictionary ×1

tlist ×1

tlistbox ×1