我想要开一个新窗口的时候,关掉之前打开的一个窗口,现在知道这个要关闭的窗口的name,怎么做??

解决方案 »

  1.   

    findwindow( nil, pchar(FormCaption) );
      

  2.   

    新建窗体的oncreate事件中加
    关闭窗口.close;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      H:THandle;
    begin
      H:=FindWindow( nil, Pchar( 'form2' ) );
      if H <> 0 then  SendMessage(h, WM_CLOSE, 0, 0);
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      Form2.Show;
    end;
      

  4.   

    我的第一个窗口是这样建立的
    pagecontrol1.ActivePageIndex:=0;
      if not Assigned(frmMZsf) then
         frmMZsf:=TfrmMZsf.Create(Application);  frmMZsf.Parent:= tabsheet1;
      frmMZsf.Show;
      lastForm:= frmMZsf.name;
    然后我开第二个窗口是这样的
    H:=FindWindow(nil, Pchar(lastForm));
      if H <> 0 then
        SendMessage(h, WM_CLOSE, 0, 0);
      pagecontrol1.ActivePageIndex:=0;
      if not Assigned(FrmMzTuiFei) then
         FrmMzTuiFei:=TFrmMzTuiFei.Create(Application);  FrmMzTuiFei.Parent:= tabsheet1;
      FrmMzTuiFei.Show;
    其中lastform是全局变量,
    但是没找到上一个窗口呢??
      

  5.   

    published
      Form2:TForm2;
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      Form2:=TForm2.Create( Owner );
      form2.Parent := self.Panel1;
      Form2.Show;
    end;
    procedure TForm1.Button4Click(Sender: TObject);
    var
      Field: ^TForm;
    begin
      Field := self.FieldAddress('Form2');
      if Field <> nil then
      begin
        Field.Close;
      end;
    end;
      

  6.   

    为什么Field总是为nil,另外,FieldAddress的参数是窗口的name还是caption??
      

  7.   

    published
    Form2:TForm2;数据成员的名称 如果要定位到TForm2参数就是FieldAddress的参数就是Form2