⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s2.tools.ts2dict.pas

📁 轉載的程序應用框架
💻 PAS
字号:
unit S2.Tools.TS2Dict;

interface

uses
  Classes, S2.Tools.TS2Object, S2.Tools.IS2DictItem, S2.Tools.TS2DictItem;

type
  TS2Dict = class;

  IS2Dict = interface
    function Find(const Name: string): TS2DictItem;
    function GetName(const Index: Integer): string;
    function GetCount: Integer;
    procedure Add(Dict: TS2Dict); overload;
    procedure Add(Item: TS2DictItem); overload;
  end;

  TS2Dict = class(TS2Object, IS2Dict)
  private 
    List: TList;
  public 
    function Find(const Name: string): TS2DictItem; virtual;
    function GetName(const Index: Integer): string;
    function GetCount: Integer; virtual;
    procedure Add(Dict: TS2Dict); overload; virtual;
    procedure Add(Item: TS2DictItem); overload; virtual;
  public
    constructor Create;
    destructor Destroy; override;
  end;

implementation

uses
  SysUtils, S2.Core.IS2Cloneable, S2.Error.S2Exception;

{ TS2Dict }

procedure TS2Dict.Add(Dict: TS2Dict);
var
  Index: Integer;
begin
  for Index := 0 to Dict.List.Count - 1 do
    List.Add(Dict.List.Items[Index]);
end;

procedure TS2Dict.Add(Item: TS2DictItem);
begin
  List.Add(Item);
end;

constructor TS2Dict.Create;
begin
  inherited;
  List := TList.Create;
end;

destructor TS2Dict.Destroy;
var
  DictItem: TS2DictItem;
begin
  while List.Count > 0 do
  begin
    DictItem := List.Items[0];
    List.Delete(0);
    FreeAndNil(DictItem);
  end;
  FreeAndNil(List); 
end;

function TS2Dict.Find(const Name: string): TS2DictItem;
var
  Index: Integer;
  DictItem: TS2DictItem;
begin
  Result := nil;
  for Index := 0 to List.Count - 1 do
  begin
    DictItem := List.Items[Index];
    if DictItem.GetName = Name then
    begin
      Result := DictItem;
      Exit;
    end;
  end;   
end;

function TS2Dict.GetCount: Integer;
begin
  Result := List.Count;
end;

function TS2Dict.GetName(const Index: Integer): string;
begin
  try
    Result := TS2DictItem(List.Items[Index]).GetName;
  except
    on E: Exception do
      raise S2Exception.Create(ClassName, 'GetName', E.Message);
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -