菜题!!!关闭一个正在create的窗口? 怪!叏!夬!希望高手进来看看!! 怎么没有给帖子加分的功能?? (20分)

  • 主题发起人 shadowno
  • 开始时间
S

shadowno

Unregistered / Unconfirmed
GUEST, unregistred user!
有form1 和form2两个窗口,form1中有一个button和一个checkbox,当我单击button时
,创建并打开form2,form2在打开的过程中检测form1中的checkbox的状态,如果被选中
,就关闭,并释放form2,如果checkbox没有被选中则继续!

部分代码如下::
////////////////////////////////////////
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,unit2;

type
TForm1 = class(TForm)
Button1: TButton;
CheckBox1: TCheckBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Application.CreateForm(Tform2, form2);
form2.ShowModal ;
end;
end.

////////////////////////////////////////
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm2 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
begin
if form1.CheckBox1.checked then
begin
form2.Close; //关不掉?????????????
end;
end;

end.




 
对关不掉的,隐藏应该可以吧
 
关不掉??????
不会吧????
释放呢?????(free 没用)我试过了!
请继续!!!
 
干吗不在form1中检测form1的checkbox的状态,符合条件才创建form2
 
不用CLOSE
用application.Terminate
 
因为form2也有限制条件要进行判断,很麻烦!
有最直接的方法吗!
最好不从程序流程上处理.
谢谢!!
 
Terminate??!%……¥#◎※……¥◎(×※
老兄我的program 要买钱的,这就Terminate了,¥#◎……%¥……※……
 
不可能在create时free掉。
另想办法吧。
 
不是吧!!
我up,up,up
 

既然由form1打开,为何不在form1中作检测呢?
Application.CreateForm(Tform2, form2);
//检测代码
form2.ShowModal ;
 
先Dispose
然後隱藏。
 
把关闭Form2的代码放在Form2的OnShow事件里,不过我真是想不通,你为
什么不写成如果checkbox被选中,则不创建Form2,而一定要写成创建以后
再关闭呢?搞不懂
 
具体原因很复杂,就不多说了!
 
同意楼上。
也可以在form2上放一timer,在create中设timer的enabled,在timer中进行判别
 
sorry!虽然只有20分,但我也应该有权说话的,哦!!

请针对问题,正面回答!

 
按照我的流程,是不是真的办不到呀????
 
用postquitMessage试试
 
怎么用 po s t quit M e s s a g e ????有希望吗???
 
顶部