我做个主窗体和三个子窗体,我主窗体放上一个按钮,我点击"下一步"按钮时,显示出第一个子窗体,隐藏主窗体,显示出来的子窗体,点击退出按钮,在回到主窗体,这个代码我会弄 具体是这样的:第一个窗体中的按钮名字为btn1 
unit Unit1; interface uses 
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
Dialogs, StdCtrls,unit2; //引用窗体2的单元文件 type 
TForm1 = class(TForm) 
btn1: TButton; 
procedure btn1Click(Sender: TObject); 
private 
{ Private declarations } 
public 
{ Public declarations } 
end; var 
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.btn1Click(Sender: TObject); 
begin 
form1.Hide; 
Form2.ShowModal; 
end; end. 
第二个窗体中按钮的名字为btn2 
unit Unit2; interface uses 
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
Dialogs, StdCtrls; type 
TForm2 = class(TForm) 
btn2: TButton; 
procedure btn2Click(Sender: TObject); 
private 
{ Private declarations } 
public 
{ Public declarations } 
end; var 
Form2: TForm2; implementation 
uses Unit1; //引用窗体一的单元文件 
{$R *.dfm} procedure TForm2.btn2Click(Sender: TObject); 
begin 
Form2.Close; 
Form1.Show; 
end; end. 
但是我要在第一个子窗体上再放一个"下一步"按钮 点击它显示出第二个子窗体 ,隐藏第一个子窗体 然后点击"返回"按钮又回到第一个子窗体 这样的步骤 就出错了 不知道为什么 不能以次类推吗?应该怎么改??

解决方案 »

  1.   

    procedure TForm1.btn1Click(Sender: TObject);
    begin
    form1.Hide;
    Form2.ShowModal;  //form2是否有创建?
    end;
      

  2.   

    要善于使用
    published
    procedure show(传递的参数);overload;
    function showmodal(你要的参数):integer;overload;
      

  3.   

    提示工程检测到错误类Einvalidoperation 错误信息cannotmake a visible window modal 进程终止  我就是把第2个窗体的"下一步"按纽换成了procedure TForm2.Button2Click(Sender: TObject);
    begin
    form2.Hide;
    Form3.ShowModal; (这里原来的form1 form2 换成了2 3)
    end;uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,unit3;(这里加了个UNIT3)
      

  4.   

    是不是在做一个向导?如果是,那么建议在一个Form上用PageControl实现。
      

  5.   

    我这3个窗体的代码都发给你们看看 哪出错了?
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, unit2, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Label1: TLabel;
        procedure Button1Click(Sender: TObject);
        procedure PageControl1Change(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    form1.Hide;
    Form2.ShowModal;
    end;procedure TForm1.PageControl1Change(Sender: TObject);
    begin
    form1.close;
    end;end.
    ------------------------------
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,unit3;type
      TForm2 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form2: TForm2;implementation
    uses Unit1;
    {$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
    begin
    Form2.Hide;
    Form1.ShowModal;
    end;procedure TForm2.Button2Click(Sender: TObject);
    begin
    form1.Hide;
    form2.Hide;
    Form3.ShowModal;
    end;end.
    --------------------------
    unit Unit3;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm3 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);  private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form3: TForm3;implementation
    uses unit2;
    {$R *.dfm}procedure TForm3.Button1Click(Sender: TObject);
    begin
    Form3.Hide;
    Form2.ShowModal;end;end.
      

  6.   

    不用ShowModal,改用Show,就不会出错了,效果也是一样的。
      

  7.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    form1.Hide;
    Form2.ShowModal;
    end;
    procedure TForm2.Button1Click(Sender: TObject);
    begin
    Form2.Hide;
    Form1.ShowModal;
    end;
    等都有问题 你在这里使用了Form2.showModal方法将窗体变成了模态窗体,可以看一下showModal方法,里面有
    if (Visible) or(not   Enabled)or (fsModal   in   FFormState)or(FormStyle=fsMDIChild) then   
     raise EInvalidOperation.Create(SCannotShowModal)
    所以可以看到你用了ShowModal后,将窗体的状态就变成了fsModal,然后当你由窗体2返回到1然后再执行form1上的按扭事件时,这时,由于form2的Formstate为fsModal然后你ShowModal就会提示这个错误了,如果你一定要这样写的话,你可以在前面加一个判断为
    if fsModal in form.FormState then
      这里就调用Show方法
    else
      调用ShowModal方法,这样就不会错了所以代码如下
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    form1.Hide;
    if fsModal in form2.FormState then
      form2.show
    else
      Form2.ShowModal;
    end;
    procedure TForm2.Button1Click(Sender: TObject);
    begin
    Form2.Hide;
    if fsModal in form1.FormState then
      form1.show
    else
    Form1.ShowModal;
    end;
    show方法不会出现这样的情况,建议如果用ShowModal方法的话,窗体就动态创建,然后在showModal方法之后释放掉
      

  8.   


    form1.hide;
      application.CreateForm(Tform2,form2);
      form2.showmodal;
    同样,
    form2.hide;
    application.createform(Tform1,form1)
    form1.showmodal;