Daher empfehle ich immer typisierte Listen...
Mach dir mal nen Project1.dpr und mach nen Loadfromfile in ne Stringliste und mach für jede Zeile nen Format( Liste[i],[Edit1.text] );
In das Edit schreibste dann einfach den Namen der Klasse (ohne das T am Anfang) für die die Liste sein soll... Hier mein "Template"
Delphi-Quellcode:
unit %sList;
interface
uses
Contnrs,
%s;
type
T%sList =
class( TObjectList )
protected
//* Protected functions..
function GetItem(
Index: Integer): T%s;
reintroduce;
procedure SetItem(
Index: Integer;
const Value: T%s);
reintroduce;
public
//* Constructors.. don't forget to call "inherited"
//constructor Create; overload;
//constructor Create(AOwnsObjects: Boolean); overload;
//* List Functions & Propertys
function Add(AObject: T%s): Integer;
reintroduce;
function Extract(Item: T%s): T%s;
reintroduce;
function Remove(AObject: T%s): Integer;
reintroduce;
function IndexOf(AObject: T%s): Integer;
reintroduce;
procedure Insert(
Index: Integer; AObject: T%s);
reintroduce;
function First: T%s;
reintroduce;
function Last: T%s;
reintroduce;
property Items[
Index: Integer]: T%s
read GetItem
write SetItem;
default;
//* Insert your own functions here...
end;
implementation
uses
Windows,
SysUtils;
{ T%sList }
function T%sList.Add(AObject: T%s): Integer;
begin
result :=
inherited Add( AObject );
end;
function T%sList.Extract(Item: T%s): T%s;
begin
result :=
inherited Extract( Item )
as T%s;
end;
function T%sList.First: T%s;
begin
result :=
inherited First
as T%s;
end;
function T%sList.GetItem(
Index: Integer): T%s;
begin
result :=
inherited GetItem(
Index )
as T%s;
end;
function T%sList.IndexOf(AObject: T%s): Integer;
begin
result :=
inherited IndexOf( AObject );
end;
procedure T%sList.Insert(
Index: Integer; AObject: T%s);
begin
inherited Insert(
Index,AObject);
end;
function T%sList.Last: T%s;
begin
result :=
inherited Last
as T%s;
end;
function T%sList.Remove(AObject: T%s): Integer;
begin
result :=
inherited Remove(AObject);
end;
procedure T%sList.SetItem(
Index: Integer;
const Value: T%s);
begin
inherited SetItem(
Index,Value);
end;
end.
Damit fällt dann das ekelige Typecasten TMyObject() weg!
Gruß
Reli