请大家帮忙看代码为什么运行到FORM2.SHOW就停止?(10分)

  • 主题发起人 delphi入门
  • 开始时间
D

delphi入门

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure Formshow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
timer1.Enabled:=false;
close;
end;

procedure TForm1.Formshow(Sender: TObject);
begin
form2.show;
end;

end.
 
Form2创建了吗?
 
你的计时器在程序运行时就打开了
并且没有什么条件就关闭了计时器,同时也关闭了Form1
这里的Form1应该是Mainform,如果Mainform关闭,则整个系统就关闭了
因此,这个程序有很大的问题!
 
对的吗。
form1显示的时候调用form.show事件,而form.show事件中显示form2,然后就停止了。
 

没有uses unit2,
Timer1Timer中不能close,可以使用self.hide

 
是不是Form2显示后退出了程序!
应该是这样运行的
你要实现什么效果呢?
注意:
你还应该在Form1中Uses Form2的
 
你们提的问题都试过,就是不执行FORM2
 
我在你的代码基础上添加了一个Uses Unit2后
一模一样的程序运行的结果是:
基本上同时显示了两个Form
过了一会儿两个Form同时消失!
不会出现不执行Form2的情况
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
begin
Form2.Show;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
Close;
end;

end.
 
那我的电脑就没有,是什么原因?
 
顶部