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