我用一个按钮,点击它时关闭窗体(是个子窗体)
子窗体是在另一个子窗体中通过下面语名创建 的!
   if Not Assigned(frmSearchPrice) then
   frmSearchPrice:=TfrmSearchPrice.Create(Application) ;
   frmSearchPrice.Show;关闭函数:
procedure TfrmSearchPrice.BtnreturnClick(Sender: TObject);
begin
   frmSearchPrice.Close;  //想通过这个函数关闭子窗体
end;
procedure TfrmSearchPrice.FormClose(Sender: TObject; var Action: TCloseAction);
  
begin
    Action:=CaFree;
end;procedure TfrmSearchPrice.FormDestroy(Sender: TObject);
begin
    frmSearchPrice:=nil;
end;

解决方案 »

  1.   

    子窗体的FormStyle设置为fsMDIChild没有。
      

  2.   

    子窗体在application中不显示,是在程序中创建的,所以直接用frmSearchPrice.Close; 是关不上的(因为程序找不到该窗体)。可以用下面的代码关闭procedure TForm1.Button2Click(Sender: TObject);
    var
      i,j:integer;
    begin
      i:=screen.FormCount;
      if i>0 then
      begin
        for j:=0 to i-1 do
        begin
          if screen.Forms[j].Name='Form2' then
            screen.Forms[j].Close;
        end;
      end;
    end;