{
for (int i = 0; i < ComponentCount; i++)
ListBox1->Items->InsertObject(0,
Components[i]->Name,
(TObject *)Components[i]);
}
void __fastcall TForm1::ListBox1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (Button == mbRight)
{
TClass ClassRef;
int Index = ListBox1->ItemAtPos(Point(X,Y), true);
// only components that are controls have a position
// make sure the component is a control
for (ClassRef = ListBox1->Items->Objects[Index]->ClassType();
ClassRef != NULL;
ClassRef = ClassRef->ClassParent())
if (String(ClassRef->ClassName()) == "TControl")
{
TControl *TheObject = (TControl *)ListBox1->Items->Objects[Index];
StatusBar1->SimpleText =
TheObject->Name + " is at (" +
IntToStr(TheObject->Left) + ", " +
IntToStr(TheObject->Top) + ")";
break;
}
if (ClassRef == NULL) // if it wasn't a control
MessageBeep(0);
}
}