unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, Types, Data.Win.ADODB, Generics.Collections, contnrs,
Vcl.StdCtrls;
type
TMyTestClass =
class
myName :
String;
myNumber : Integer;
end;
TMyObjectList =class( TObjectList)
end;
TGenericTestList = TList<TMyTestClass>;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function DoSomething_with_TObjectList ( aMyObjectList : TMyObjectList) : boolean;
begin
// .....
result := true;
end;
function DoSomething_with_TGenericList ( aGenericTestList : TGenericTestList) : boolean;
begin
// .....
result := true;
end;
procedure TForm1.Button1Click(Sender: TObject);
var MyObject: TMyTestClass;
MyList: TMyObjectList;
MyGenericTestList : TGenericTestList;
Begin
MyObject := TMyTestClass.Create;
MyList := TMyObjectList.Create(True);
MyList.Add(MyObject);
MyGenericTestList := TGenericTestList.create;
MyGenericTestList.Add (MyObject);
//operating code....
DoSomething_with_TObjectList( TMyObjectList( MyGenericTestList));
DoSomething_with_TGenericList( TGenericTestList ( MyGenericTestList));
MyList.Free;
end;
end