Form1中有个Button1
按了Button1效果是Form1关闭了,然后又重新打开了。
前提:是关闭,不是简单的HIDE SHOW
代码要运行通过的。
谢谢!

解决方案 »

  1.   


      Close;
      ShellExecute(0, 'open', PChar(Application.exeName), nil, nil , SW_SHOWNORMAL);
      

  2.   

      
      ShellExecute(0, 'open', PChar(Application.exeName), nil, nil , SW_SHOWNORMAL);
      Close;
      

  3.   

    你的回答中,要是程序只有一个窗体下是可能会对,但我的Form1只是程序中的一个普通窗体,不是主窗体!
    而且这个代码,我放在不同地方不一定结果一样!
      

  4.   

    那你为什么要CLOSE不要HIDE? 
      

  5.   

    hide的话,窗体的代码不会再重新构建
    就是说里面用到变量的话,貌似是不会改变的,有用到数据库连接的。
    我想要的就是先关了,再打开。HIDE SHOW行的话,我也就不会发帖求救了
      

  6.   

    如果只是有变量的话,那就简单了,也不必这么复杂了,关键还是找一个好的思路来解决问题。可以自己建立一个pas单元,把变量放在里面。
      

  7.   


      Close;
      TForm(ClassType.NewInstance).Create(Owner).Show;不过从问问题的方式看,你用这段代码还会出现别的问题的
      

  8.   

    只能說你的思路是個錯誤的。實再不行,你就先創建一個新的,再CLOSE,反正看情形,你是想清楚這個窗體下的變量。
      

  9.   


    form1:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,Unit3;
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        procedure OpenForm2(var Msg: TMessage); Message WM_USER01;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.OpenForm2(var Msg: TMessage);
    begin
      if not assigned(form2) then
         form2 := TForm2.create(Application);
      form2.showmodal;
      form2.free;
      form2 := nil;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      PostMessage(Form1.Handle, WM_USER01, 0, 0);
    end;end.form2:
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm2 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form2: TForm2;implementationuses Unit1, Unit3;{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
    begin
      Close;
      PostMessage(Form1.Handle, WM_USER01, 0, 0);
    end;end.unit3:
    unit Unit3;interface
    uses Messages;
    const
      WM_USER01 = WM_USER + 8001;implementationend.不知这样是否可以满足你的要求
      

  10.   

    FreeAndNil(Form1);
    Form1 := TForm1.Create(Application);
      

  11.   

    ShellExecute(0, 'open', PChar(Application.exeName), nil, nil , SW_SHOWNORMAL);
    Close;
      

  12.   

    Application.Terminate;
    ShellApi.ShellExecute(Application.Handle,'Open', PChar(Application.exeName),GetCommandLineA,'',SW_SHOWNORMAL);