02-01-2010, 05:19 PM
ابداء من هنا :
كود :
unit AListBox;
interface
uses
SysUtils, Classes, Controls, StdCtrls;
type
TAListBoxItem = class; //<-- here
TAListBoxItems = class; // <-- here
TAListBox = class(TListBox)
private
{ Private declarations }
FItems: TAListBoxItems;
procedure SetItems(Items: TAListBoxItems);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(aOwner: TComponent); override;
destructor Destroy(); override;
published
{ Published declarations }
Property Items : TAListBoxItems Read FItems Write SetItems;
end;
//----> added
TAListBoxItem = class(TCollectionItem)
private
{ Private declarations }
FCaption: String;
// from here u can add what u want ...!
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(collection: TCollection); override;
published
{ Published declarations }
Property Caption : String Read FCaption Write FCaption;
end;
// ---> added
TAListBoxItems = class(TCollection)
private
FManager: TAListBox;
protected
function GetOwner(): TPersistent; override;
public
constructor Create(manager: TAListBox);
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TAListBox]);
end;
{ TAListBox }
{ TAListBoxItem }
constructor TAListBoxItem.Create(collection: TCollection);
begin
inherited Create(collection);
FCaption :='';
end;
{ TAListBoxItems }
constructor TAListBoxItems.Create(manager: TAListBox);
begin
inherited Create(TAListBoxItem);
FManager := manager;
end;
function TAListBoxItems.GetOwner: TPersistent;
begin
result := FManager;
end;
{ TAListBox }
constructor TAListBox.Create(aOwner: TComponent);
begin
inherited Create(aOwner);
FItems := TAListBoxItems.Create(self);
end;
destructor TAListBox.Destroy;
begin
FItems.Free();
inherited Destroy();
end;
procedure TAListBox.SetItems(Items: TAListBoxItems);
begin
FItems.Assign(Items);
end;
end.
