谢谢

解决方案 »

  1.   

    var
      fm : TForm2;
    begin 
      fm := Tform2.Create(nil);
      if fm.ShowModal = mrOK then
      begin
        .....
      end
      else
      begin
        ....
      end;
    end;
      

  2.   

    谢谢,如何我要让form2返回数据哪???
      

  3.   

    你仔细点看上面的代码. fm.ShowModal = mrOk ,很明显, ShowModal 就可以返回数据...
    但这个数据是整型. 在 Form2 中直接对 ModalResult 赋值就可以关闭窗体了.
      

  4.   

    按照楼上的方法是不能返回参数的
    看这个//....省略
    type
      TForm2 = class(TForm)
      private
    //r作为一个中间的数值进行计算,计算结果经过返回参数返回调用位置
        r: string;
      public
      end;
    //从其他模块运行以下函数ShowForm2调用模块2
    //参数说明:FHcs 返回参数;CRcs:传入参数
    function ShowForm2(var FHcs: string;CRcs:string): Boolean;
    var
      Form2: TForm2;implementation{$R *.DFM}function ShowForm2(var FHcs: string;CRcs:string): Boolean;
    begin
      with TForm2.Create(Application) do
      try
        r:=CRcs;
        Result := (ShowModal = mrOk);
      finally
        FHcs :=r;//返回处理完毕的中间值
        Free;
      end;
    end;//确定按钮
    procedure TForm2.Button1Click(Sender: TObject);
    begin
      ModalResult := MB_OK;
      Close;
    end;//中间过程,处理中间值r
    procedure TForm2.Button2Click(Sender: TObject);
    begin
     r:=r+'红尘';
    end;//form1中,调用ShowForm2
    procedure TForm1.Button1Click(Sender: TObject);
    var s:string;
    begin
      if ShowFormDY(s,Label1.Caption)=true then
        Label1.Caption:=s;
    end;在以上程序中,假设form1.label1.caption显示为"醉恋",那么在form1按下按钮button1以后,显示form2,在from2按下按钮button2,然后按下button1关闭form2以后,form1的label.caption就被更新为"醉恋红尘"。
    我说的这麽详细不知道你看懂了没有?