我作了个快闪窗体,上面按了个label,倒计时显示用,到0就自动关闭这个快闪。
时间控件interval值为1000。
但一运行,label不是5、4、3、2、1这么走,而是5、4、2、0吧嗒到了:(  郁闷!!
加了self.repaint self.refresh也还是不行。
主窗体里也有个时间控件,但应该与这个快闪窗体的不冲突吧?
下面是快闪窗体的代码,请高手指点迷津。unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ComCtrls;type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  i:integer;
implementation
uses
  main;
{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
begin  if (i<0) and (self.Label2.Visible=true) then
  begin
    self.Close;
  end;
  label2.Caption:=inttostr(i);
  i:=i-1;end;procedure TForm1.FormCreate(Sender: TObject);
begin
  i:=5;
end;end.

解决方案 »

  1.   

    label2.Caption:=inttostr(i);
    Application.processMessage;
      i:=i-1;
      

  2.   

    你看看你main单元里的代码吧。
      

  3.   

    应该跟你main的代码有关,这段代码是正确的,不然你新建一个工程试试就知道了
      

  4.   

    如楼上,
    把变量i 作为一个全局变量的名称不是一个好的习惯,
    一般i 都是内部使用的局部变量,如果在main单元中访问i就会
    引起混乱了
      

  5.   

    Application.processMessage;这句话什么意思?加上了也还是不行。
    这段代码在独立的一个工程里的确没啥问题,但作为快闪就是不行。各位上眼,我把main的代码和application的代码都贴出来。
    //applicaiton
    program QQFormDemo;uses
      Forms,
      SysUtils,
      Main in 'Main.pas' {frmMain},
      Unit1 in 'Unit1.pas' {Form1};{$R *.res}
    var
     welcomeform:TForm1;
    begin
      welcomeform:=tform1.Create(nil);
      welcomeForm.Show;
      welcomeform.Update;   //如果窗体内有图片文字,必须有这一举  Application.Initialize;
      Application.Title := 'OraCharC';
      Application.CreateForm(TfrmMain, frmMain);
      Application.CreateForm(TForm1, Form1);
      //welcomeForm.Close;
      Application.Run;end.
    /////////////////////main//////////////////////////////////
    unit Main;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      ExtCtrls, StdCtrls, Dialogs, Registry,unit1;type
      TfrmMain = class(TForm)
        tmrMouseOut: TTimer;
        RadioButton1: TRadioButton;
        RadioButton2: TRadioButton;
        Button1: TButton;
        procedure MouseLeaveProc(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure RadioButton1Click(Sender: TObject);
        procedure RadioButton2Click(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      protected
        procedure WMMOVING(var Msg: TMessage); message WM_MOVING;
        procedure MouseEnterProc(var Msg: TMessage); message CM_MOUSEENTER;
      public
        { Public declarations }
      end;var
      frmMain: TfrmMain;implementation{$R *.dfm}
    {
    ****************************
    * 以下为窗口效果相关过程 *
    ****************************
    }
    //限制窗口的Top不能小于0,即窗口不能被拖动到顶部以外procedure TfrmMain.WMMOVING(var Msg: TMessage);
    begin
      inherited;
      //当窗口被移动的时候
      if PRECT(Msg.lParam).Top < 0 then
        PRECT(Msg.lParam).Top := 0;
    end;//实现窗口自动弹出procedure TfrmMain.MouseEnterProc(var Msg: TMessage);
    begin
      inherited;  tmrMouseOut.Enabled := True;
      //如果窗口不是隐藏的,不用弹出。
      if Self.Top >= 0 then
        Exit;
      Self.Top := 0;
      Msg.Result := 0;
    end;//实现窗口自动隐藏procedure TfrmMain.MouseLeaveProc(Sender: TObject);
    var
      pt: TPoint;
    begin
      GetCursorPos(pt);
      if (not PtInRect(Self.BoundsRect, pt)) and (GetAsyncKeyState(VK_LButton) <> 0) then
        Exit;
      if PtInRect(Self.BoundsRect, pt) then
        Exit;  tmrMouseOut.Enabled := False;  //如果窗口不在最顶部,不用隐藏。
      if Self.Top > 0 then
        Exit;  //将窗口上缩,只显示三个像素
      Self.Top := -Self.Height + 3;
    end;
    {
    ****************************
    * 以上为窗口控制相关过程 *
    ****************************
    }
    ................
    //操作部分就不贴了:)
      

  6.   

    先Application.Initialize再创建welcomeform
      

  7.   

    先Application.Initialize再创建welcomeform
    ===========
    我就是这么干的啊~~
    我的welcomform叫“form1”,主窗体叫“frmMain”。
    并且我还曾经试着设inteval为100,计数器从50开始往下减,这样取最左边的一位数字,这样就可以5、4、3、2、1、0的到了,但我发现这个速度变得很快,根本就不是5秒,也就2秒多一点。
    怪啊~~~~~~~~~
      

  8.   

    你Create了不止一个窗体。是Delphi建立的,你没注意。它也没Show出来。
    估计你的I是全局的。
    application的代码都贴出来。
    //applicaiton
    program QQFormDemo;uses
      Forms,
      SysUtils,
      Main in 'Main.pas' {frmMain},
      Unit1 in 'Unit1.pas' {Form1};{$R *.res}
    var
     welcomeform:TForm1;
    begin
      welcomeform:=tform1.Create(nil);
      welcomeForm.Show;
      welcomeform.Update;   //如果窗体内有图片文字,必须有这一举  Application.Initialize;
      Application.Title := 'OraCharC';
      Application.CreateForm(TfrmMain, frmMain);
      Application.CreateForm(TForm1, Form1); ////这行你去掉就OK了。
      //welcomeForm.Close;
      Application.Run;
      

  9.   

    引用:
    begin
    welcomeform:=tform1.Create(nil);
    welcomeForm.Show;
    welcomeform.Update; //如果窗体内有图片文字,必须有这一举Application.Initialize;
    Application.Title := 'OraCharC';
    Application.CreateForm(TfrmMain, frmMain);
    Application.CreateForm(TForm1, Form1);
    //welcomeForm.Close;
    Application.Run;end.
    这段代码是不会等待你的 timer 的,同步执行的 ,也就是说  你welcomeForm
    还没有  close  TfrmMain和 TForm1 已经创建了,如果你正的要停  5妙,在
    welcomeForm  可以写  sleep(5000) //API 函数