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;