unit ChoiceRoom;interfaceuses
  Windows, Messages, SysUtils, Buttons, Classes,Forms,StdCtrls,
  Grids,DBGrids, DBCtrls, Mask;type
  TChoiceRoom = class(TComponent)
  private    FHouseNum:String;
    procedure CancelClick(Sender: TObject);
    procedure OkClick(Sender: TObject);  protected
    { Protected declarations }
  public    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;  published    function Execute():String;  end;procedure Register;implementationprocedure Register;
begin
  RegisterComponents('Hotel', [TChoiceRoom]);
end;constructor TChoiceRoom.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;destructor TChoiceRoom.Destroy;
begin
  inherited Destroy;
end;function TChoiceRoom.Execute():string;
var
 GroupBox1:TGroupBox;
 GroupBox2:TGroupBox;
 FormChoice:TForm;
begin  FormChoice := TForm.Create(Application);
  with FormChoice do
  begin
    Name := 'FormChoice';
    Caption := '请选择一个帐户';
    Height := 367;
    Width := 497;
    BorderStyle := bsDialog;
    Position := poOwnerFormCenter;    GroupBox1 := TGroupBox.Create(self);
    with GroupBox1 do
    begin
      Parent := FormChoice;
      Caption := '请输入查询条件:';
      Top := 8;
      Left := 8;
      Height := 65;
      Width := 473;
    end;    with TLabel.Create(self) do
    begin
      Parent := GroupBox1;
      Name := 'Label1';
      Caption := '房号:';
      Top := 32;
      Left := 16;
      Height := 13;
      Width := 36;
    end;    with TLabel.Create(self) do
    begin
      Parent := GroupBox1;
      Name := 'Label2';
      Caption := '宾客姓名:';
      Top := 32;
      Left := 120;
      Height := 13;
      Width := 60;
    end;    with TLabel.Create(self) do
    begin
      Parent := GroupBox1;
      Name := 'Label3';
      Caption := '帐号:';
      Top := 32;
      Left := 280;
      Height := 13;
      Width := 36;
    end;    with TEdit.Create(self) do
    begin
      Parent := GroupBox1;
      Name := 'ERoomNum';
      Text := '';
      Top := 29;
      Left := 56;
      Height := 13;
      Width := 57;
    end;    with TEdit.Create(self) do
    begin
      Parent := GroupBox1;
      Name := 'EGuestName';
      Text := '';
      Top := 29;
      Left := 184;
      Height := 13;
      Width := 89;
    end;    with TEdit.Create(self) do
    begin
      Parent := GroupBox1;
      Name := 'ERoomCnt';
      Text := '';
      Top := 29;
      Left := 312;
      Height := 13;
      Width := 89;
    end;    with TBitBtn.Create(self) do
    begin
      Parent := GroupBox1;
      Name := 'BitBtn1';
      Caption := '查询';
      Top := 16;
      Left := 416;
      Height := 41;
      Width := 49;
    end;    with TDBGrid.Create(self) do
    begin
      Parent := FormChoice;
      Name := 'BDGrid1';
      Top := 80;
      Left := 8;
      Height := 129;
      Width := 473;
    end;    with TCheckBox.Create(self) do
    begin
      Parent := FormChoice;
      Name := 'chkEmpty';
      Caption := '空房';
      Checked := False;
      Enabled := False;
      Top := 216;
      Left := 16;
      Height := 17;
      Width := 60;
    end;    with TCheckBox.Create(self) do
    begin
      Parent := FormChoice;
      Name := 'chkBooking';
      Caption := '预订';
      Checked := False;
      Enabled := False;
      Top := 216;
      Left := 80;
      Height := 17;
      Width := 60;
    end;    with TCheckBox.Create(self) do
    begin
      Parent := FormChoice;
      Name := 'chkstay';
      Caption := '在店';
      Checked := False;
      Enabled := False;
      Top := 216;
      Left := 144;
      Height := 17;
      Width := 60;
    end;    with TCheckBox.Create(self) do
    begin
      Parent := FormChoice;
      Name := 'chkCheckout';
      Caption := '已结';
      Checked := False;
      Enabled := False;
      Top := 216;
      Left := 208;
      Height := 17;
      Width := 60;
    end;    with TCheckBox.Create(self) do
    begin
      Parent := FormChoice;
      Name := 'chkGroup';
      Caption := '团队房';
      Checked := False;
      Enabled := False;
      Top := 216;
      Left := 272;
      Height := 17;
      Width := 60;
    end;    with TCheckBox.Create(self) do
    begin
      Parent := FormChoice;
      Name := 'chkRepair';
      Caption := '维修房';
      Checked := False;
      Enabled := False;
      Top := 216;
      Left := 344;
      Height := 17;
      Width := 60;
    end;    with TCheckBox.Create(self) do
    begin
      Parent := FormChoice;
      Name := 'chkClose';
      Caption := '关闭房';
      Checked := False;
      Enabled := False;
      Top := 216;
      Left := 416;
      Height := 17;
      Width := 60;
    end;    GroupBox2 := TGroupBox.Create(self);
    with GroupBox2 do
    begin
      Parent := FormChoice;
      Caption := '';
      Top := 232;
      Left := 8;
      Height := 105;
      Width := 401;
    end;    with TLabel.Create(self) do
    begin
      Parent := GroupBox2;
      Name := 'Label4';
      Caption := '备注:';
      Top := 16;
      Left := 8;
      Height := 13;
      Width := 36;
    end;    with TLabel.Create(self) do
    begin
      Parent := GroupBox2;
      Name := 'Label5';
      Caption := '旅行社/公司备注:';
      Top := 40;
      Left := 8;
      Height := 13;
      Width := 101;
    end;    with TDBEdit.Create(self) do
    begin
      Parent := GroupBox2;
      Name := 'DBEdtMemo';
      Text := '';
      Top := 16;
      Left := 48;
      Height := 21;
      Width := 345;
    end;    with TDBMemo.Create(self) do
    begin
      Parent := GroupBox2;
      Name := 'DBEdtCoMemo';
      Text := '';
      Top := 56;
      Left := 48;
      Height := 41;
      Width := 345;
    end;    with TBitBtn.Create(self) do
    begin
      Parent := FormChoice;
      Name := 'BitBtn2';
      Caption := '确定';
      Top := 240;
      Left := 416;
      Height := 25;
      Width := 67;
      OnClick := OkClick;
    end;    with TBitBtn.Create(self) do
    begin
      Parent := FormChoice;
      Name := 'BitBtn3';
      Caption := '取消';
      Top := 272;
      Left := 416;
      Height := 25;
      Width := 67;
      OnClick := CancelClick;
    end;    with TBitBtn.Create(self) do
    begin
      Parent := FormChoice;
      Name := 'BitBtn4';
      Caption := '帮助';
      Top := 304;
      Left := 416;
      Height := 25;
      Width := 67;
    end;    ShowModal;
    Result := FHouseNum;
  end;
end;procedure TChoiceRoom.CancelClick(Sender: TObject);
begin
  FHouseNum := '';
  TBitBtn(Sender).Parent.free ;
end;procedure TChoiceRoom.OkClick(Sender: TObject);
begin
  FHouseNum := '1111';
  TBitBtn(Sender).Parent.free ;
end;
end.当点击BitBtn1或BitBtn2后,FormChoice被释放掉了,但应用程序不能获得焦点,程序界面定死不能进行任何操作,如果点击FormChoice能正常关闭该窗体,但发现窗体没有被正常释放。
请问怎么解决?还是我的设计思路有问题?

解决方案 »

  1.   

    上面书写有误
    ————————————————————————————
    当点击BitBtn1或BitBtn2后,FormChoice被释放掉了,但应用程序不能获得焦点,程序界面定死不能进行任何操作,如果点击FormChoice窗口上的关闭图标能正常关闭该窗体,但发现窗体没有被正常释放。请问怎么解决?还是我的设计思路有问题?
      

  2.   

    改成 TForm.CreateNew(Application)
    另外 TForm((Sender as TComponent).Parent).Closel
      

  3.   

    执行到TForm((Sender as TComponent).Parent).Close提示parent没有定义。
    使用TForm(Sender as TComponent).Parent.Close提示close方法没有定义,但用showmessage(TForm(Sender as TComponent).Parent.Name)显示的却是FormChoice,百思不得其解啊。
      

  4.   

    在释放的时候再加一句
    主窗体.setfocus好了
      

  5.   

    问题已解决,请 aiirii(ari-淘金坑) 到此接分。谢谢!