TObjectList<T>アプリのオブジェクト リスト間で共通の機能を処理する子孫を作成したいと考えています。次に、必要に応じて追加機能を導入するために、その新しいクラスからさらに派生したいと考えています。複数レベルの継承を使用して機能させることができないようです。おそらくジェネリックをもう少し理解する必要がありますが、成功せずにこれを行う正しい方法を高低で検索しました。これまでの私のコードは次のとおりです。
unit edGenerics;
interface
uses
  Generics.Collections;
type
  TObjectBase = class
  public
    procedure SomeBaseFunction;
  end;
  TObjectBaseList<T: TObjectBase> = class(TObjectList<T>)
  public
    procedure SomeOtherBaseFunction;
  end;
  TIndexedObject = class(TObjectBase)
  protected
    FIndex: Integer;
  public
    property Index: Integer read FIndex write FIndex;
  end;
  TIndexedObjectList<T: TIndexedObject> = class(TObjectBaseList<T>)
  private
    function GetNextAutoIndex: Integer;
  public
    function Add(AObject: T): Integer;
    function ItemByIndex(AIndex: Integer): T;
    procedure Insert(AIndex: Integer; AObject: T);
  end;
  TCatalogueItem = class(TIndexedObject)
  private
    FID: integer;
  public
    property ID: integer read FId write FId;
  end;
  TCatalogueItemList = class(TIndexedObjectList<TCatalogueItem>)
  public
    function GetRowById(AId: Integer): Integer;
  end;
implementation
uses
  Math;
{ TObjectBase }
procedure TObjectBase.SomeBaseFunction;
begin
end;
{ TObjectBaseList<T> }
procedure TObjectBaseList<T>.SomeOtherBaseFunction;
begin
end;
{ TIndexedObjectList }
function TIndexedObjectList<T>.Add(AObject: T): Integer;
begin
  AObject.Index := GetNextAutoIndex;
  Result := inherited Add(AObject);
end;
procedure TIndexedObjectList<T>.Insert(AIndex: Integer; AObject: T);
begin
  AObject.Index := GetNextAutoIndex;
  inherited Insert(AIndex, AObject);
end;
function TIndexedObjectList<T>.ItemByIndex(AIndex: Integer): T;
var
  I: Integer;
begin
  Result := Default(T);
  while (Count > 0) and (I < Count) and (Result = Default(T)) do
    if Items[I].Index = AIndex then
      Result := Items[I]
    else
      Inc(I);
end;
function TIndexedObjectList<T>.GetNextAutoIndex: Integer;
var
  I: Integer;
begin
  Result := 0;
  for I := 0 to Count - 1 do
    Result := Max(Result, Items[I].Index);
  Inc(Result);
end;
{ TCatalogueItemList }
function TCatalogueItemList.GetRowById(AId: Integer): Integer;
var
  I: Integer;
begin
  Result := -1;
  for I := 0 to Pred(Self.Count) do
    if Self.Items[I].Id = AId then
    begin
      Result := I;
      Break;
    end;
end;
end.
/////// ERROR HAPPENS HERE ////// ???? why is beyond me
次の宣言のようです。
>>> TCatalogueItemList = class(TIndexedObjectList<TCatalogueItem>) <<<<
次のコンパイラ エラーが発生します。
[DCC エラー] edGenerics.pas(106): E2010 互換性のない型: 'TCatalogueItem' および 'TIndexedObject'
ただし、コンパイラは、宣言自体ではなく、コンパイルされたユニットの END (106 行目) にエラーを表示します。これは私には意味がありません...
基本的には、必要に応じて新しい機能で拡張できる TObjectList から派生したジェネリック リストがあるという考えです。これに関するヘルプは素晴らしいでしょう!!!
Delphi 2010 を使用して追加する必要があります。
ありがとう。