procedure OpenChildForm(FormClass: TFormClass; var Fm; AOwner:TComponent);能否将var Fm 换成 Fm:string 如何写??????? 或 String to var 在传入
uses Unit2;procedure TForm1.OpenForm(FormName: string); var Component: TComponent; begin Component := Application.FindComponent(FormName); if (Component is TForm) and (Component.Name = FormName) then TForm(Component).Show; end;procedure TForm1.Button1Click(Sender: TObject); begin OpenForm('Form2'); end;不要忘记引用要开打窗体的单元
procedure OpenChildForm(FormClass: TFormClass; var Fm; AOwner:TComponent); begin Application.CreateForm(FormClass,TForm(Fm)); end;能否将var Fm 换成 Fm:string 如何写??????? 或 String to var 在传入
想要 procedure OpenChildForm(FormClass: TFormClass; Fm:string ; AOwner:TComponent); begin Application.CreateForm(FormClass,TForm(Fm)); end;TForm(Fm)一定要
var :引用传递; in :传入(值传递); out :引用传递(只传出);
to wolf2005() yes
var s: string; t: Variant; begin s := 'aaa'; t := Variant(s); //这里就是String to Variant ShowMessage(VarToStr(t)); end;
或 String to var 在传入
var
Component: TComponent;
begin
Component := Application.FindComponent(FormName);
if (Component is TForm) and (Component.Name = FormName) then
TForm(Component).Show;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
OpenForm('Form2');
end;不要忘记引用要开打窗体的单元
procedure OpenChildForm(FormClass: TFormClass; var Fm; AOwner:TComponent);
begin
Application.CreateForm(FormClass,TForm(Fm));
end;能否将var Fm 换成 Fm:string 如何写???????
或 String to var 在传入
procedure OpenChildForm(FormClass: TFormClass; Fm:string ; AOwner:TComponent);
begin
Application.CreateForm(FormClass,TForm(Fm));
end;TForm(Fm)一定要
in :传入(值传递);
out :引用传递(只传出);
s: string;
t: Variant;
begin
s := 'aaa';
t := Variant(s); //这里就是String to Variant
ShowMessage(VarToStr(t));
end;
千万别用variant类型,太慢了,不信你可以试试
begin
Application.CreateForm(FormClass,TForm(objCreateForm));
TForm(objCreateForm).ShowModal;
FreeAndNil(TForm(objCreateForm));
end;procedure TForm1.Button1Click(Sender: TObject);
begin
OpenChildForm(TForm2,'Form2',nil);
end;
var
FormClass: TFormClass;
begin
if not Assigned(ChildForm) then
begin
FormClass := TFormClass(GetClass(ChildClass));
if Assigned(FormClass) then
ChildForm := FormClass.Create(Application);
ChildForm.BorderStyle := bsNone;
ParentControl.Height := ChildForm.ClientHeight - 25;
end;
ChildForm.BorderStyle := bsNone;
ChildForm.Parent := ParentControl;
ChildForm.Align := alClient;
ChildForm.Visible := true;
Result := true;
end;
調用
SetChildForm(Panel1, TForm(_FormMenu), 'T_FormMenu');在_FormMenu的最後加上
initialization
RegisterClass(T_FormMenu);
finalization
UnRegisterClass(T_FormMenu);大概就是如此, 你可自己修改