Mir ist noch nicht so ganz klar, was eigentlich erreicht werden soll, aber vieleicht so als Anregung:
Delphi-Quellcode:
type
TMyObj1 = class(TObject)
A:integer;
end;
TMyObj2 = class(TMyObj1)
B:string;
end;
TMyList = class(TObjectList)
procedure verarbeite; virtual; abstract;
end;
TMyList1 = class(TMyList)
procedure verarbeite; override; {verarbeitet tmyobj1}
end;
TMyList2 = class(TMyList) {oder class(TMyList1)}
procedure verarbeite; override; {verarbeitet tmyobj2}
end;
TMyRich = class(TRichEdit)
private
FMylist: TMyList;
function GetMyList: TMyList;
protected
function CreateList: TMyList; virtual; abstract;
public
property mylist: TMyList read GetMyList;
destructor Destroy; override;
end;
TMyRich1 = class(TMyRich)
protected
function CreateList: TMyList; override;
end;
TMyRich2 = class(TMyRich)
protected
function CreateList: TMyList; override;
end;
implementation
destructor TMyRich.Destroy;
begin
FMylist.Free;
inherited;
end;
function TMyRich.GetMyList: TMyList;
begin
if FMylist = nil then
FMylist := CreateList;
Result := FMylist;
end;
function TMyRich1.CreateList: TMyList;
begin
Result := TMyList1.Create;
end;
function TMyRich2.CreateList: TMyList;
begin
Result := TMyList2.Create;
end;