这是一些我认为可以工作的未经测试的代码。让我们将您的组件称为 TMyComponent。作为组件编辑器和/或属性编辑器的一部分,您必须在 TMyComponent 的设计时包中创建您的 TMyComponentTest1Form。
然后,尝试像这样创建 TMyComponentTest1Form:
function TMyComponentTest1.Execute: Boolean;
var
aForm: TMyComponentTest1Form;
OwnerForm: TForm;
aMyComponent: TMyComponent;
begin
{OwnerForm is your main design form}
OwnerForm := nil;
{Get your component on the main design form}
aMyComponent := TMyComponent(GetComponent(0))
{Make sure your component's owner is a TForm}
if (aMyComponent.Owner is TForm) then
OwnerForm := TForm(aMyComponent.Owner);
{You problem may be solved by making component form owner the Application}
aForm := TMyComponentTest1Form.Create(Application);
try
{
Now you should be able iterate the components owned by OwnerForm
right here. If you do not want to do it here, add a TForm property
to your component and assign OwnerForm to it.
}
aForm.ShowModal;
finally
aForm.Free;
end;
end;