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

📄 etylist.pas

📁 数据库封装原代码 1. 该代码可以免费使用, 该代码的名字暂时定为"哲别" 2. 如果你需要使用该代码, 请注明该代码的原来作者: Jacky Zhou 3. 如果你发现该代码有bug,可以自己修改
💻 PAS
字号:
unit EtyList;

interface

uses
    Classes, Entity;

type
  TEtyList = class
  private
    m_List : TInterfaceList;
    m_strEntityName : String;

    function Validate(nIndex : Integer) : Boolean;
  public
    constructor Create(ety : IEntity) overload;

    function GetEntityName() : String;
    function GetEntityCount() : Integer;

    function AddEntity(ety : IEntity) : Integer;
    function RemoveEntity(nIndex : Integer) : Integer;
    function GetEntity(nIndex : Integer) : IEntity;

    procedure Clear;

    procedure Exchange(nIndex1 : Integer; nIndex2 : Integer);
  end;

  PTEtyList = ^TEtyList;

implementation

//-----------------------------------------------------------------------------
//                              Create
//-----------------------------------------------------------------------------
constructor TEtyList.Create(ety : IEntity);
begin
  inherited Create;

  m_List := TInterfaceList.Create;
  m_strEntityName := ety.EntityName;
end;

//-----------------------------------------------------------------------------
//                              GetEntityName
//-----------------------------------------------------------------------------
function TEtyList.GetEntityName() : String;
begin
  Result := m_strEntityName;
end;

//-----------------------------------------------------------------------------
//                              GetEntityCount
//-----------------------------------------------------------------------------
function TEtyList.GetEntityCount() : Integer;
begin
  Result := m_list.Count;
end;

//-----------------------------------------------------------------------------
//                              AddEntity
//-----------------------------------------------------------------------------
function TEtyList.AddEntity(ety : IEntity) : Integer;
begin
  Result := m_List.Add(ety);
end;

//-----------------------------------------------------------------------------
//                              RemoveEntity
//-----------------------------------------------------------------------------
function TEtyList.RemoveEntity(nIndex : Integer) : Integer;
begin
  try
    if Validate(nIndex) then
      Result := m_List.Remove(m_List.Items[nIndex])
    else
      Result := -1;
  except
    Result := -1;
  end;
end;

//-----------------------------------------------------------------------------
//                              GetEntity
//-----------------------------------------------------------------------------
function TEtyList.GetEntity(nIndex : Integer) : IEntity;
begin
  try
    if Validate(nIndex) then
      Result := IEntity(m_List.items[nIndex])
    else
      Result := nil;
  except
    Result := nil;
  end;
end;

//-----------------------------------------------------------------------------
//                              Validate
//-----------------------------------------------------------------------------
function TEtyList.Validate(nIndex : Integer) : Boolean;
begin
  try
    if (nIndex < 0) or (nIndex > m_List.Count - 1) then
      Result := false
    else
      Result := true;
  except
    Result := false;
  end;
end;

//-----------------------------------------------------------------------------
//                              Clear
//-----------------------------------------------------------------------------
procedure TEtyList.Clear;
begin
  //bug, Clear does not really release the memoery
  m_List.Clear;
end;

//-----------------------------------------------------------------------------
//                              Exchange
//-----------------------------------------------------------------------------
procedure TEtyList.Exchange(nIndex1 : Integer; nIndex2 : Integer);
begin
  m_List.Exchange(nIndex1, nIndex2);
end;

end.


⌨️ 快捷键说明

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