关于ShowModal(100)

Discussion in '用户界面' started by 墨剑, Aug 4, 2009.

  1. hh

    hhjjhhjj Member

    Apr 1, 2015
    If FrmSample <> Nil then
    FreeAndNil(FrmSample);
    Application.CreateForm(TFrmSample, FrmSample);
    With FrmSampledo
    begin
    try ShowModal;
    finally FreeAndNil(FrmSample);
    end;
    end;
     
  2. 幸福人生1

    幸福人生1 Member

    Apr 1, 2015
    这是我用的根据窗体的类名创建窗体的函数,你可以参考一下,应该能帮到你。function TfrmMain.ShowForm(frmClassName: string): THandle;varfrmcls: Tformclass;cc: TPersistentclass;frm: Tform;i: Integer;
    begin
    Result := 0;try cc := Getclass(frmClassName);
    frmcls := TFormClass(cc);Exceptend;
    for i := 0 to MDIChildCount - 1do
    begin
    if UpperCase(frmClassName) = UpperCase(MDIChildren.ClassName) then
    begin
    MDIChildren.BringToFront; Exit; end;
    end;
    frm := frmcls.create(self);case frm.FormStyle of fsMDIChild: begin
    frm.show; Result := frm.Handle; end;
    fsNormal: begin
    frm.ShowModal; FreeAndNil(frm); end;
    end;
    end;
     
  3. ae

    aert Member

    Apr 1, 2015
    Code (Text):
    1. if application.FindComponent(FormName)=nil then
    2.   begin
    3.     FormName:=TFormName.create(application) ;
    4.    FormName.Show;
    5.  endelse
    6.   if not FormName.Showing then
    7.     FormName.Show;
    试试看
     
  4. ha

    hanyuhen1 Member

    Apr 1, 2015
    你要父窗体这里要创建窗体时,连到底要创建什么窗体都不知道搞毛要多传递一个参数代表是哪种子类窗体就OK了
     
  5. 墨剑

    墨剑 Member

    Apr 1, 2015
    窗体变量已经指明了他是什么用的窗口
     
  6. 墨剑

    墨剑 Member

    Apr 1, 2015
    换个思路来说,现在要修改form的 showmodal方法,让这个方法实现先检查窗口是否为nil,如果为nil则先建立,接着再显示窗口。 你怎么写?
     
  7. Pa

    Passion Member

    Apr 1, 2015
    Delphi不会为普通变量名建立RTTI,因此你无法从一个值为nil的Form1变量得到其类型TForm1,更别谈创建TForm1了。楼主还是退一步吧,总得想法传来一个TForm1类或字符串做必要的类型信息,然后再根据这个信息去创建TForm1的实例。
     
  8. Pa

    Passion Member

    Apr 1, 2015
    或者你干脆把这些窗体变量全写在published的property里,用RTTI来动态获得其类型,就好办了。
     
  9. li

    liuls Member

    Apr 1, 2015
    ShowModal;
    只要你确定它关闭释放就行了, 你就不用管它是否为 nil 了;
    因为你不关闭模态窗口是没办下法执行其它窗口的(除非直接发送消息)父类写一个类函数或者 Public 区域的;
    这样子类都可以调用TParentForm = class(TForm)public class procedure Execute(...);
    end;
    // 实现class procedure TParentForm.Execute(...);
    begin
    With Self.Create(nil)do
    try ShowModal;
    finally Free;
    end;
    end;
    TSonForm = class(TParentForm) // ....end;
    // 要调用 TSonForm 的 显示TSonForm.Execute;
    即可
     
  10. Su

    Supermay Member

    Apr 1, 2015
    学习ingprocedure iFormmodal(InstanceClass: TComponentClass;
    var Reference);var Instance: TComponent;
    begin
    Instance := TComponent(InstanceClass.NewInstance);
    TComponent(Reference) := Instance;
    try Instance.Create(nil);
    TForm(Instance).ShowModal ;
    TForm(Instance).BringToFront;
    finally TForm(Instance).Free;
    TForm(Instance) := nil;
    end;
    end;
    调用iFormmodal(Tform2,form2);
    iFormmodal(Tform3,form3);
     
  11. zw

    zwz_good Member

    Apr 1, 2015
    需要传递类变量参数才行,示例如下:type TForm2 = class(TForm)//父窗体 end;
    TForm2Class = class of TForm2;
    ////父窗体元类 TForm3 = class(TForm2) //子窗体1 end;
    TForm4 = class(TForm2) //子窗体2 end;
    ======================================//调用type TForm1 = class(TForm) btn1: TButton;
    btn2: TButton;
    procedure btn1Click(Sender: TObject);
    private procedure showForm2(AFormClass: TForm2Class);
    end;
    -------------procedure TForm1.btn1Click(Sender: TObject);
    begin
    showForm2(TForm3);
    end;
    procedure TForm1.showForm2(AFormClass: TForm2Class);
    begin
    with AFormClass.Create(nil)do
    begin
    ShowModal;
    Free;
    end;
    end;
     
  12. vi

    violetxh Member

    Apr 1, 2015
    给你一个函数,我是在PageControl中显示的在Form上放一个cxPageControl 所有的Form 都显示在sheet 上,如果Form 已经存在则将它调到到最前面我正在用,非常好用兴趣和我联系QQ:14564807procedure TMainForm.ShowForm_Tab(FormClass: TFormClass;
    form:Tform;
    Flag:string);
    //窗口融合 function GetFlag(Flag:string):Boolean;
    var x,u: Integer;
    begin
    Result:=False;
    for x := 0 to pgc.ControlCount - 1do
    if pgc.Controls[x] is TcxTabSheet then
    for u := 0 to TcxTabSheet(pgc.Controls[x]).ControlCount - 1do
    if (TcxTabSheet(pgc.Controls[x]).Controls is TForm) and (TForm(TcxTabSheet(pgc.Controls[x]).Controls).Name=Flag) then
    begin
    Result:=True;
    Break;
    end;
    end;
    var i:Integer;
    begin
    Form := FormClass.Create(Application);
    form.Color:=RGB(255,255,255);
    if not GetFlag(Flag) then
    begin
    Form.Name:=Flag;
    tabsheet:=TcxTabSheet.Create(nil);
    Tabsheet.ParentColor:=True;
    Tabsheet.Name:=Flag+'1';
    Tabsheet.Caption:=Form.Caption;
    Tabsheet.PageControl:=PGC;
    pgc.ActivePage:=Tabsheet;
    Form.Parent:=Tabsheet;
    Form.Align:=alClient;
    Form.BorderStyle:=bsNone;
    Form.Show;
    end else
    begin
    For i:=0 to pgc.PageCount-1do
    if pgc.Pages.Name=Flag+'1' then
    begin
    pgc.Pages.TabVisible:=True;
    pgc.ActivePage:=pgc.Pages;
    Exit;
    end;
    end;
    end;
    调用试例procedure TMainForm.CGGL_ActionExecute(Sender: TObject);
    begin
    ShowForm_Tab(TCGGL_Frm,CGGL_Frm,'CGGL_Frm');
    end;