stoxx hat in
diesem Beitrag eine Version dieses Templates vorgestellt, das sich einfach und ohne die
jedi.inc benutzen lässt:
Delphi-Quellcode:
{$IFDEF DEVELOP_NEVER} // never define
unit templateTListU;
interface
uses
Sysutils,
Classes,
Contnrs;
type
_TObjectListItem = TObject;
{$ENDIF DEVELOP_NEVER}
{$IFDEF _DECLARE_SECOND_PASS}
{$DEFINE _SECOND_PASS}
{$UNDEF _DECLARE_SECOND_PASS}
{$ENDIF _DECLARE_SECOND_PASS}
{$IFNDEF _SECOND_PASS}
type
_TObjectlist =
class
private
protected
fList: TObjectList;
function GetItems(_Idx: integer): _TObjectListItem;
function GetCount: integer;
public
constructor Create;
destructor Destroy;
override;
function Add(_Item: _TObjectListItem): integer;
function Remove(_Item: _TObjectListItem): integer;
procedure Clear;
property Items[_Idx: integer]: _TObjectListItem
read GetItems;
default;
property Count: integer
read GetCount;
end;
{$DEFINE _DECLARE_SECOND_PASS}
{$ENDIF _SECOND_PASS}
{$IFDEF DEVELOP_NEVER}
implementation
{$ENDIF DEVELOP_NEVER}
{$IFDEF _SECOND_PASS}
{ _TObjectlist }
constructor _TObjectlist.Create;
begin
inherited Create;
fList := TObjectList.Create;
end;
destructor _TObjectlist.Destroy;
begin
fList.Free;
inherited;
end;
function _TObjectlist.Add(_Item: _TObjectListItem): integer;
begin
Result := fList.Add(_Item);
end;
function _TObjectlist.Remove(_Item: _TObjectListItem): integer;
begin
Result := fList.Remove(_Item);
end;
procedure _TObjectlist.Clear;
begin
fList.clear;
end;
function _TObjectlist.GetItems(_Idx: integer): _TObjectListItem;
begin
Result := fList[_Idx]
as _TObjectListItem;
end;
function _TObjectlist.GetCount: integer;
begin
Result := fList.Count;
end;
{$UNDEF _SECOND_PASS}
{$ENDIF _Second_PASS}
//{$WARNINGS off}
Ein kleines Beispiel in Form einer streng typisierten Liste von Labels hat er auch gleich mitgeliefert:
Delphi-Quellcode:
unit u_MemoList;
interface
uses
Sysutils,
Classes,
Contnrs,
StdCtrls;
type
_TObjectListItem = TMemo;
{$I templateTListU.pas}
TMemoList =
class(_TObjectList)
end;
implementation
{$I templateTListU.pas}