zoukankan      html  css  js  c++  java
  • 一个继承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;

  • 相关阅读:
    Oracle 在64位机器上使用plSQL连接Oracle的问题(SQL*Net not properly installed)
    Bytes to be written to the stream exceed the Content-Length bytes size specified 解决方法
    Eclipse下建立geoserver源码工程
    (转)HttpWebRequest以UTF-8编码写入内容时发生“Bytes to be written to the stream exceed the Content-Length bytes size specified.”错误
    为nginx创建windows服务自启动
    (转)Nginx反向代理设置 从80端口转向其他端口
    从SNE到t-SNE再到LargeVis
    K NEAREST NEIGHBOR 算法(knn)
    从0开始用python实现神经网络 IMPLEMENTING A NEURAL NETWORK FROM SCRATCH IN PYTHON – AN INTRODUCTION
    Python和数据科学的起步指南
  • 原文地址:https://www.cnblogs.com/liujicai/p/4323480.html
Copyright © 2011-2022 走看看