类声明部分:

TDMSTrains = class(TList)
private
FHashed: Boolean;
FHashList: TFpHashList;
FOwnsObjects: Boolean;
FSorted: Boolean;
FUpdateLevel: Integer;
protected
function GetItem(Index: Integer): TDMSTrain;
procedure Notify(Ptr: Pointer; Action: TListNotification); override;
procedure SetItem(Index: Integer; AObject: TDMSTrain);
public
constructor Create; overload;
constructor Create(AOwnsObjects: Boolean;Hashed:Boolean;AutoSorted:boolean);
overload;
destructor Destroy; override;
function Add(AObject: TDMSTrain): Integer;
procedure BeginUpdate;
procedure EndUpdate;
function Extract(Item: TDMSTrain): TDMSTrain;
function Find(const ATrainId:string): TDMSTrain;
function First: TDMSTrain;
function IndexOf(AObject: TDMSTrain): Integer;
procedure Insert(Index: Integer; AObject: TDMSTrain);
function Last: TDMSTrain;
function Remove(AObject: TDMSTrain): Integer;
property Items[Index: Integer]: TDMSTrain read GetItem write SetItem;
default;
property OwnsObjects: Boolean read FOwnsObjects write FOwnsObjects;
property UpdateLevel: Integer read FUpdateLevel;
end;

实现部分:

{
********************************** TDMSTrains **********************************
}
constructor TDMSTrains.Create;
begin
inherited Create;
FOwnsObjects := True;
FHashList:=TFpHashList.Create;
FHashed:=True;
FSorted:=True;
end;

constructor TDMSTrains.Create(AOwnsObjects: Boolean;Hashed:Boolean;
AutoSorted:boolean);
begin
inherited Create;
FHashList:=TFpHashList.Create;
FOwnsObjects := AOwnsObjects;
FHashed:=Hashed;
FSorted:=AutoSorted;
end;

destructor TDMSTrains.Destroy;
begin
inherited;
FHashList.Free;
end;

function TDMSTrains.Add(AObject: TDMSTrain): Integer;
begin
Result := inherited Add(AObject);
end;

procedure TDMSTrains.BeginUpdate;
begin
Inc(FUpdateLevel);
end;

procedure TDMSTrains.EndUpdate;
begin
if FUpdateLevel>0 then
Dec(FUpdateLevel);
if (FUpdateLevel=0) and FSorted then
Sort(SortTrainBy_PSTLJ_TRAINTYPE_ASC);
end;

function TDMSTrains.Extract(Item: TDMSTrain): TDMSTrain;
begin
Result := TDMSTrain(inherited Extract(Item));
end;

function TDMSTrains.Find(const ATrainId:string): TDMSTrain;
begin
Result:=TDMSTrain(FHashList.Find(ATrainid));
end;

function TDMSTrains.First: TDMSTrain;
begin
Result := TDMSTrain(inherited First);
end;

function TDMSTrains.GetItem(Index: Integer): TDMSTrain;
begin
Result := inherited Items[Index];
end;

function TDMSTrains.IndexOf(AObject: TDMSTrain): Integer;
begin
Result := inherited IndexOf(AObject);
end;

procedure TDMSTrains.Insert(Index: Integer; AObject: TDMSTrain);
begin
inherited Insert(Index, AObject);
end;

function TDMSTrains.Last: TDMSTrain;
begin
Result := TDMSTrain(inherited Last);
end;

procedure TDMSTrains.Notify(Ptr: Pointer; Action: TListNotification);
var
T: Integer;
begin
if FHashed then
begin
if (Action=lnDeleted)then
begin
T:=FHashList.FindIndexOf(TDMSTrain(Ptr).name);
if T<>-1 then
FHashList.Delete(T);
if OwnsObjects then
TDMSTrain(Ptr).Free;
end else if (Action=lnAdded) then
begin
FHashList.Add(TDMSTrain(Ptr).name,Ptr);
if (FUpdateLevel=0) and FSorted then
Sort(SortTrainBy_PSTLJ_TRAINTYPE_ASC);
end;
end;
inherited Notify(Ptr, Action);
end;

function TDMSTrains.Remove(AObject: TDMSTrain): Integer;
begin
Result := inherited Remove(AObject);
end;

procedure TDMSTrains.SetItem(Index: Integer; AObject: TDMSTrain);
begin
inherited Items[Index] := AObject;
end;

最新文章

  1. [转]PhpStorm 超强语言模板的支持
  2. sqlplus运行sql文件
  3. AnguarJS 第一天----Hello World
  4. wf(七)(手把手包会)
  5. Python基础之--常用模块
  6. 安卓开发_浅谈Android动画(一)
  7. Linux下 ntp 时间同步服务ntpd 出现 the NTP socket is in use, exiting 解决
  8. 查看Android应用签名信息
  9. Fence Repair
  10. WORDPRESS 后台500错误解决方法集合
  11. 使用PuTTY在Windows中向Linux上传文件
  12. Yii框架AR对象数据转化为数组
  13. C++在struct与class差异
  14. Java单链表实现
  15. 提取Jar2Exe源代码,JavaAgent监控法
  16. 华为oj之字符串分割
  17. SVG笔记
  18. kubernetes命令详情
  19. ionic中 ng-repeat下使用ng-model获取不到选中数据问题:
  20. 【HDU 5858】Hard problem(圆部分面积)

热门文章

  1. 旅行家的预算 1999年NOIP全国联赛普及组NOIP全国联赛提高组
  2. SpringMVC——form标签的使用
  3. elasticsearch的marvel
  4. oracle 左边填充函数使用
  5. 文件hash数据库
  6. javascript性能优化总结一(转载人家)
  7. C++中没有finally,那么应该在如何关闭资源
  8. 解决bash: mysql: command not found 的方法
  9. angularjs jquery thinkPHP3.2.3 相结合小实例
  10. MyEclipse中查询