📄 etylist.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 + -