凭感觉写的,没有实际测试,参考一下吧,应该可以的
function showform(aform:tform;acontrol:twincontrol):tform;
begin
result :=nil;
if Not assigned(form2) then
with tform(aform).create(application) do begin
parent:= acontrol;
Color:= MainPanel.Color;
show;
end;
result:= form2;
end;
function showform(aform:tform;acontrol:twincontrol):tform;
begin
result :=nil;
if Not assigned(form2) then
with tform(aform).create(application) do begin
parent:= acontrol;
Color:= MainPanel.Color;
show;
end;
result:= form2;
end;
begin
if not Assigned(mFormClass) then Exit;
if not Assigned(mForm) then
try
mForm := mFormClass.Create(Application);
except
mForm.Free;
end;
mForm.Parent := MainPanel;
mForm.Colo r:= MainPanel.Color;
mForm.show;
NodeForm := mForm;
end;procedure TForm1.Button1Click(Sender: TObject);
var
vForm: TForm;
begin
vForm := nil;
CreateMyFrom(TForm, vForm);
end;
var
Instance: TForm;
begin
Instance := TForm(AForm);
if Not Assigned(Instance) then
begin
Instance := AFormClass.Create(Application);
TForm(AForm) := Instance;
With Instance do
begin
Parent := AParentControl;
Color := TForm(AParentControl).Color;
Show;
end;
NodeForm := Instance;
end;
end;调用时
ShowForm(TForm1, Form1, MainForm.MainPanel);
begin
if FindGlobalComponent(FormName) <> nil then exit;
Application.CreateForm(FormClass,Reference); if Aform <> nil then
Aform.Release; Aform := (FindGlobalComponent(FormName) as TForm); Aform.parent := Fmain.panel1;
Aform.align := alclient;
Aform.show;
end;procedure CloseForm;
begin
if Aform <> nil then
Aform.close;
Aform := nil;
end;
AControl: TWinControl; AColor: TColor): TForm;
begin
Result := nil;
if not Assigned(AForm) then
with TForm(AForm).Create(Application) do begin
Parent := AControl;
Color := AColor;
Show;
end;
Result := AForm;
end;