|
Форуми -> Програмування -> delphi templates - list
|
{$IFNDEF TYPED_OBJECT_LIST_TEMPLATE}
unit u_list;
interface
uses
Sysutils,
Classes,
Contnrs;
type
_TYPED_OBJECT_LIST_ITEM_ = TObject;
{$ENDIF TYPED_OBJECT_LIST_TEMPLATE}
{$IFNDEF TYPED_OBJECT_LIST_TEMPLATE_SECOND_PASS}
type
_TYPED_OBJECT_LIST_ = class
protected
fList: TObjectList;
function GetItems(_Idx: integer): _TYPED_OBJECT_LIST_ITEM_;
function GetCount : integer;
public
constructor Create;
destructor Destroy; override;
function Add(_Item: _TYPED_OBJECT_LIST_ITEM_): integer;
property Items[_Idx: integer]: _TYPED_OBJECT_LIST_ITEM_
read GetItems; default;
property Count : integer read GetCount;
end;
{$ENDIF TYPED_OBJECT_LIST_TEMPLATE_SECOND_PASS}
{$IFNDEF TYPED_OBJECT_LIST_TEMPLATE}
implementation
{$DEFINE TYPED_OBJECT_LIST_TEMPLATE_SECOND_PASS}
{$ENDIF TYPED_OBJECT_LIST_TEMPLATE}
{$IFDEF TYPED_OBJECT_LIST_TEMPLATE_SECOND_PASS}
{ _TYPED_OBJECT_LIST_ }
constructor _TYPED_OBJECT_LIST_.Create;
begin
inherited Create;
fList := TObjectList.Create;
end;
destructor _TYPED_OBJECT_LIST_.Destroy;
begin
fList.Free;
inherited;
end;
function _TYPED_OBJECT_LIST_.Add(
_Item: _TYPED_OBJECT_LIST_ITEM_): integer;
begin
Result := fList.Add(_Item);
end;
function _TYPED_OBJECT_LIST_.GetItems(
_Idx: integer): _TYPED_OBJECT_LIST_ITEM_;
begin
Result := fList[_Idx] as _TYPED_OBJECT_LIST_ITEM_;
end;
function _TYPED_OBJECT_LIST_.GetCount : integer;
begin
Result := fList.Count;
end;
{$WARNINGS off}
{$IFNDEF TYPED_OBJECT_LIST_TEMPLATE}
end.
{$ENDIF TYPED_OBJECT_LIST_TEMPLATE}
{$ENDIF TYPED_OBJECT_LIST_TEMPLATE_SECOND_PASS}
{$DEFINE TYPED_OBJECT_LIST_TEMPLATE_SECOND_PASS}
|
|
приклад використання =)
unit u_panelitem_info_list;
interface
Uses
Windows,
Contnrs,
Graphics;
type
TPanelItemInfo = class(TObject)
private
FFileExt : string;
FDrawColor : TColor;
public
constructor Create(const AFileExt : string; ADrawColor : TColor);
property FileExt : string read FFileExt write FFileExt;
property DrawColor : TColor read FDrawColor write FDrawColor;
end;
{$define TYPED_OBJECT_LIST_TEMPLATE}
_TYPED_OBJECT_LIST_ITEM_ = TPanelItemInfo;
{$include 'u_list.pas'}
TPanelItemInfoList = class(_TYPED_OBJECT_LIST_)
end;
implementation
constructor TPanelItemInfo.Create(const AFileExt : string; ADrawColor : TColor);
begin
FFileExt := AFileExt;
FDrawColor := ADrawColor;
end;
{$include 'u_list.pas'}
end.
|
|
а потім далі в програмі...
uses u_panelitem_info_list;
...
FPanelItemInfoList : TPanelItemInfoList;
...
FPanelItemInfoList.Add(TPanelItemInfo.Create('ini', clRed));
...
і так далі =))
|
|
Книга Фріланс на західному ринку
|
|