我写了一个API,应该可以满足你的要求:function CreateAndShowForm(const AOwner: TComponent; const TfrmClass: TCustomFormClass): TModalResult; begin with TfrmClass.Create(AOwner) do try Name := ClassName + IntToStr(Handle); //万一需要多次创建,保证窗口名称唯一 Result := ShowModal; finally Free; end; end;其中,TCustomFormClass声明如下: type TCustomFormClass = class of TCustomForm;
begin
with TfrmClass.Create(AOwner) do
try
Name := ClassName + IntToStr(Handle); //万一需要多次创建,保证窗口名称唯一
Result := ShowModal;
finally
Free;
end;
end;其中,TCustomFormClass声明如下:
type
TCustomFormClass = class of TCustomForm;