我用的DELPHI5,在父窗体中建有下拉菜单,通过下拉菜单弹出子窗体。现在有个问题,我在子窗体中要单击某一按钮后弹出另一个窗体,并将新弹出窗体中选择的某一内容传递到子窗体的某一文本框内。请问这个新窗体是否也设为子窗体?如何传值?

解决方案 »

  1.   

    假设你的新窗体名为frmSelect并且是模式窗体(即动态创建的),子窗体名为frmMachine,{1.先在你的子窗体中新增一个函数:}
    function TfrmMachine.ShowSelctForm(vForm: TfrmSelect): String;
    begin
      with vForm do
      try
        ShowModal;
        if ModalResult =mrOk then
          result :=s;
      finally
        Free;
      end;
    end;{2.在新的窗体中定义一个变量S:String,然后这样写代码;}
    procedure TfrmSelect.Action_OKExecute(Sender: TObject);
    begin
      s:='你的赋值';
      ModalResult :=mrOK;//确定
    end;procedure TfrmSelect.Action_CancelExecute(Sender: TObject);
    begin
      ModalResult :=mrCancel;//取消
    end;{3.你的子窗体这样调用新的窗体并传回值:}
    procedure TfrmMachine.Button1Click(Sender: TObject);
    begin
    text1.Text :=ShowSelctForm(TfrmSelectMc.Create(nil));
    end;