Author: Tomas Rutkauskas How to pick from a list of TPanels in a TListBox and display the selected panel Answer: 1 unit Unit1; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, 7 Dialogs, ExtCtrls, StdCtrls; 8 9 type 10 TForm1 = class(TForm) 11 ListBox1: TListBox; 12 procedure ListBox1Click(Sender: TObject); 13 private 14 { Private declarations } 15 FPanelList: TList; 16 FActivePanel: TPanel; 17 public 18 { Public declarations } 19 constructor Create(AOwner: TComponent); override; 20 destructor Destroy; override; 21 end; 22 23 var 24 Form1: TForm1; 25 26 implementation 27 28 {$R *.DFM} 29 30 {TForm1} 31 32 constructor TForm1.Create(AOwner: TComponent); 33 var 34 i: integer; 35 TempPanel: TPanel; 36 begin 37 inherited; 38 FPanelList := TList.Create; 39 for i := 0 to 20 do 40 begin 41 TempPanel := TPanel.Create(self); 42 TempPanel.Caption := 'TPanel' + IntToStr(i); 43 Listbox1.Items.Add(TempPanel.Caption); 44 FPanelList.Add(TempPanel); 45 end; 46 end; 47 48 destructor TForm1.Destroy; 49 var 50 i: integer; 51 begin 52 for i := FPanelList.Count - 1 downto 0 do 53 TPanel(FPanelList[i]).Free; 54 FPanelList.Free; 55 inherited; 56 end; 57 58 procedure TForm1.ListBox1Click(Sender: TObject); 59 begin 60 if FActivePanel <> nil then 61 FActivePanel.Parent := nil; 62 FActivePanel := FPanelList[ListBox1.ItemIndex]; 63 FActivePanel.Parent := self; 64 end; 65 66 end.