Пытаюсь создать обертку для TCategoryPanelGroup, чтобы можно было добавлять и удалять панели через коллекцию, но после добавления 3 панели вылезает ошибка: "List index out of bounds(3)". Из-за чего такое происходит, не могу понять. И хотелось бы понять как добавляются панели через PopUp меню - "New Panel", искал в исходниках дельфи, но не нашел. | Код | unit PanelsGroupM; interface uses System.SysUtils, System.Classes, Vcl.Controls, Vcl.Forms, Vcl.ExtCtrls; type TPanelGroup = class; TCatPanelsGroup = class; TPanelItem = class(TCollectionItem) private FPanelGroup: TPanelGroup; FPanel: TCategoryPanel; public constructor Create(Collection: TCollection); override; destructor Destroy; override; published property Panel: TCategoryPanel read FPanel write FPanel; end; TPanelGroup = class(TCollection) private FCatPanelsGroup: TCatPanelsGroup; function GetItem(Index: Integer): TPanelItem; procedure SetItem(Index: Integer; const Value: TPanelItem); protected function GetOwner: TPersistent; override; public constructor Create(CatPanelsGroup: TCatPanelsGroup); function Add: TPanelItem; property Items[Index: Integer]: TPanelItem read GetItem write SetItem; default; end; TCatPanelsGroup = class(TCategoryPanelGroup) private FPanels: TPanelGroup; procedure SetPanels(const Value: TPanelGroup); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property PanelItems: TPanelGroup read FPanels write SetPanels; end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TCatPanelsGroup]); end; { TPanelItem } constructor TPanelItem.Create(Collection: TCollection); begin inherited Create(Collection); FPanelGroup:=GetOwner as TPanelGroup; FPanel:=TCategoryPanel.Create(FPanelGroup.FCatPanelsGroup); FPanel.Caption:='My Panel'; FPanel.PanelGroup:=FPanelGroup.FCatPanelsGroup; end; destructor TPanelItem.Destroy; begin FreeAndNil(FPanel); inherited; end; { TPanelGroup } function TPanelGroup.Add: TPanelItem; begin Result := TPanelItem(inherited Add) end; constructor TPanelGroup.Create(CatPanelsGroup: TCatPanelsGroup); begin inherited Create(TPanelItem); FCatPanelsGroup := CatPanelsGroup; end; function TPanelGroup.GetItem(Index: Integer): TPanelItem; begin Result := TPanelItem(inherited GetItem(Index)); end; function TPanelGroup.GetOwner: TPersistent; begin Result := FCatPanelsGroup; end; procedure TPanelGroup.SetItem(Index: Integer; const Value: TPanelItem); begin inherited SetItem(Index, Value); end; { TCatPanelsGroup } constructor TCatPanelsGroup.Create(AOwner: TComponent); begin inherited; FPanels:=TPanelGroup.Create(self); end; destructor TCatPanelsGroup.Destroy; begin FreeAndNil(FPanels); inherited; end; procedure TCatPanelsGroup.SetPanels(const Value: TPanelGroup); begin FPanels.Assign(Value); end; end.
|
|