Hola.
Creo que el cargar los punteros a formularios dentro del ListBox te va a simplificar el asunto, te pongo un ejemplo :
Código Delphi
[-]
....
uses Unit2, Unit3, Unit4, Unit5;
procedure TForm1.LoadForms;
var
i : Integer;
begin
ListBox1.Clear;
for i := Screen.FormCount-1 downto 0 do
if Screen.Forms[i] <> Self then
begin
Screen.Forms[i].Parent := Panel1;
Screen.Forms[i].Show;
end;
for i := Screen.FormCount-1 downto 0 do
if Screen.Forms[i].Showing and ( Screen.Forms[i] <> Self ) then
ListBox1.AddItem( Screen.Forms[i].Caption, Pointer(Screen.Forms[i]) );
Randomize;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
LoadForms;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
const
COLORS: array[0..3] of TColor = (clRed, clLime, clYellow, clBlue);
var
i, ix: Integer;
begin
ix := ListBox1.ItemIndex; if ListBox1.ItemIndex <> -1 then
begin
for i := 0 to ListBox1.Count-1 do
TForm(ListBox1.Items.Objects[i]).Color := clBtnFace;
if ix <> -1 then
TForm(ListBox1.Items.Objects[ix]).Color := Colors[ix];
end;
end;
procedure TForm1.btnMergeClick(Sender: TObject);
var
i, x: Integer;
begin
for i := 0 to ListBox1.Items.Count-1 do
begin
x := Random(ListBox1.Items.Count);
ListBox1.Items.Move(i, x);
end;
end;
Salida del ejemplo:
De este modo simpre habrá correspondencia entre el nombre mostrado en el ListBox y el objeto sobre el que accionar, espero te sirva.
Saludos