主题:一个DELPHI小问题
190824
[专家分:0] 发布于 2007-06-17 09:18:00
我的第一个界面是一个欢迎界面我设置的大于5秒自动跳入第2界面然后我在第二个界面的ONSHOW事件中写入FORM1.CLOSE;为什么关不了啊,别的窗体用这种方法都能关闭.我每次都得用结束程序关它,怎么才能在第二个界面弹出时把它关了啊第一界面程序如下
procedure TForm1.Timer1Timer(Sender: TObject);
begin
spinEdit1.Value:=spinedit1.Value+1;
if spinedit1.Value>=5 then begin
Timer1.Enabled:=FALSE;
FORM2.SHOW;
end;
end;
end.
哪位能给解决一下呀,麻烦了?
此帖转自:[url]http://www.programfan.com/team/team.asp?team_id=1382[/url]
回复列表 (共12个回复)
沙发
长尾兔 [专家分:3630] 发布于 2007-06-17 09:56:00
楼主:你必须知道工程文件里用Application.CreateForm方法创建的第一个窗体是主窗体,在你的工程里,你的欢迎界面就被你作为了主窗体。这样做不是正统的作法。当然,如果你实在需要这样做,那你需要在你的第二个窗体的关闭事件里写application.Terminate;这样你的主窗体就会收到关闭的消息。
过一会我给你写一个我喜欢的作法。
板凳
长尾兔 [专家分:3630] 发布于 2007-06-17 10:03:00
//工程文件
program Project1;
uses
Forms, windows,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
Application.Initialize;
Form1 := TForm1.Create(nil);
try
Form1.ShowModal;
Application.CreateForm(TForm2, Form2);
finally
Form1.Free;
end;
Application.Run;
end.
//窗体一的单元。窗体一是
3 楼
长尾兔 [专家分:3630] 发布于 2007-06-17 10:04:00
//窗体一的单元。窗体一是欢迎窗体
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Interval := 5000;// 5秒后欢迎界面消失
Timer1.Enabled := True;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Self.ModalResult := mrOK;
end;
end.
//窗体二的单元。窗体二是你的“主窗体”
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm2 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
end.
4 楼
190824 [专家分:0] 发布于 2007-06-17 14:27:00
我在第二个窗体中加入Application.termnate;就不能弹出第三个窗体了整个程序就关了不行啊
5 楼
长尾兔 [专家分:3630] 发布于 2007-06-17 15:01:00
呵呵.........
你只要明白意思就行了, 呵呵, 具体还有没有第四个第五个第六个窗体, 都是无关紧要的.
实在不行你就按我的代码写不就行了嘛, 呵呵.
默认: 主窗体关闭就结束进程. 记住!
6 楼
长尾兔 [专家分:3630] 发布于 2007-06-17 15:04:00
或许你的欢迎界面是要连续欢迎好几次的. 就象进一家饭店, 大门上有人欢迎光临, 二门上还有, 进了餐室还有服务员站在那里欢迎.......呵呵:
不想让窗体用完就释放, 可以Hide它.
7 楼
190824 [专家分:0] 发布于 2007-06-17 16:05:00
太感谢了我只能给你多多的加分了我刚才试者改了一下工程文件可是虽说关了可弹不出第三个窗体拉您看我的工程文件怎么改就能把第二个窗体作为主窗体了'
工程文件:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form1},
Unit3 in 'Unit3.pas' {Form1},
Unit4 in 'Unit4.pas' {Form1},
Unit5 in 'Unit5.pas' {Form1},
Unit6 in 'Unit6.pas' {Form1},
Unit7 in 'Unit7.pas' {Form1} ;
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForm3, Form3);
Application.CreateForm(TForm4, Form4);
Application.CreateForm(TForm5, Form5);
Application.CreateForm(TForm6, Form6);
Application.CreateForm(TForm7, Form7);
Application.Run;
end.
8 楼
190824 [专家分:0] 发布于 2007-06-17 17:05:00
主窗体可以在弹出第二个窗体时自动隐藏吗具体怎么实现啊
9 楼
长尾兔 [专家分:3630] 发布于 2007-06-17 19:44:00
晕。前面不是给你一个工程文件吗?看不懂?那我照你的写:
---------------------------------------------
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2},
Unit3 in 'Unit3.pas' {Form3},
Unit4 in 'Unit4.pas' {Form4},
Unit5 in 'Unit5.pas' {Form5},
Unit6 in 'Unit6.pas' {Form6},
Unit7 in 'Unit7.pas' {Form7};
{$R *.res}
begin
Application.Initialize;
form1 := TForm1.Create(nil);
form1.ShowModal;
form1.Free;
//Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);//第一个CreateForm的窗体就是主窗体
Application.CreateForm(TForm3, Form3);
Application.CreateForm(TForm4, Form4);
Application.CreateForm(TForm5, Form5);
Application.CreateForm(TForm6, Form6);
Application.CreateForm(TForm7, Form7);
Application.Run;
end.
--------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
end.
-----------------------------------------
unit Unit2;
interface
uses
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;
implementation
uses Unit3;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
form3.Show;
self.Hide;
end;
-----------------------------------------------
//以下Form3.4.5.6照Form2的内容依次类推
-------------------------------------------------
unit Unit7;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm7 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form7: TForm7;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm7.Button1Click(Sender: TObject);
begin
form2.show;//重新显示主窗体Form2, 这样,关闭Form2就结束整个进程了
self.Hide;
end;
end.
10 楼
190824 [专家分:0] 发布于 2007-06-17 21:07:00
太感谢了问题解决了,您设置的时间
1Timer1.Interval :=5000;// 5秒后欢迎界面消失
Timer1.Enabled := True;
5000就是5秒吗我怎么改成20000000000它也是停留那么长时间就跳到下一界面呀?
2,您的意思就是主窗体不能被下一窗体Formonclose掉是吧
3您每次都给我把头文件写上
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Spin, jpeg;
type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
SpinEdit1: TSpinEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Timer1Timer(Sender: TObject);
procedure Image1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
这些东西不是自动生成的吗您的用意是什么呀?
让您见笑了我是个不折不扣的菜鸟,我是学电子的做的是计算机的毕业设计,前一阵光准备研究生复试了也没怎么看,不过我发现我对这个越来越感兴趣了,给您添麻烦了,再次表示感谢
我来回复