从控件面板Additional上拖一个TApplicationEvents到Form上就可以了.

解决方案 »

  1.   

    OnIdle事件在我的电脑上似乎无法正常运行,必须移动鼠标才会激发该事件。怎么办
      

  2.   

    什么样算空闲?没有键盘和鼠标操作吗?
    如果是这样你可以在ApplicationEvents控件的onmessage事件中捕获键盘和鼠标操作,如有一段时间没有,就起动相应的函数,不过我想得用thread线程来做。
    以便随时开起和终止。
      

  3.   

    我只是需要程序在不停地运行一个函数,而当有系统消息时(比如move或reSize)就优先处理消息函数。Application.ProcessMessage不好用。
    这个在c++builder中很容易做到,但是在delphi中怎么这么困难
      

  4.   

    在.dpr文件中放回调函数!
      

  5.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        ApplicationEvents1: TApplicationEvents;
        procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ApplicationEvents1Idle(Sender: TObject;
      var Done: Boolean);
    begin
        //你的函数。
    end;end.
      

  6.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        ApplicationEvents1: TApplicationEvents;
        procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ApplicationEvents1Idle(Sender: TObject;
      var Done: Boolean);
    begin
    //你的函数。
    end;end.
      

  7.   

    拜托……
    为什么ApplicationOnIdle在不动键盘或者鼠标的时候不会发生~!!
    难道是我的delphi的问题?
      

  8.   

    双击 ActionList, 新增一个项, 该新增项的 OnUpdate 事件是在Idle的时候不停地触发的, 然后, 随便放一个按钮, 将按钮的Action属性设为ActionList里新增的项就OK了
      

  9.   

    上面的代码我没有进行过测试,不好意思了,提供另一个建议;1、定义定时器Timer1。
    2、把TApplicationEvents控件(在Additional上)拉到Form上。
    2、编写TApplicationEvents的OnMessage脚本void __fastcall TForm1::OnMessage(...)
    {
      Timer1->Enabled=false;
      Timer1->Enabled=true;//只要收到消息就重置定时器
    }void __fastcall TForm1::Timer1OnTimer(...)
    {
      //如果定时器被触发,证明用户已经有一段时间没有用过你的程序了。
    }
      

  10.   

    大家都说得太烦了,其实DELPHI也很容易做到:
    1 放一个actionlist控件上去,就是standard最右边那个
    2 随便定义一个动作,把你要执行的代码放到该动作的onupdate事件中,这个事件会在程序空闲时执行。
      

  11.   

    我在此谢谢大家提供的建议。但是似乎这些方法都不能达到我所希望的效果。
    经过努力,我通过在dpr文件中写一个“WinMain”函数完成该功能。效果还不错,但是不保证用了只后delphi中别的功能不受影响(比如onidle事件)。程序如下:program Project1;uses
      windows,
      messages,
      Forms,
      Unit1 in 'Unit1.pas' {Form1};{$R *.res}
    var
      msg : TMSG;
      done: boolean;begin
    //这两行是原来就有的
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
    //删除Application.Run;  done:=false;//以下是消息循环
      while not done do
      if (PeekMessage(Msg,0,0,0,PM_REMOVE)) then
        if msg.message=WM_QUIT then done:=true else
        begin
          TranslateMessage(msg);
          DispatchMessage(msg);
        end
      else
        if Application.Active then
        begin
          //加入空闲时调用的函数
          Form1.Idle;  //这个是在Form1中自己定义的函数
        end;end.
      

  12.   

    如果再做一个线程,我还不如用timeSetEvent函数呢。
    程序总是会运行错误,太麻烦了
      

  13.   

    如果再做一个线程,我还不如用timeSetEvent函数呢。
    程序总是会运行错误,太麻烦了
      

  14.   

    处理idle消息的部分是隐含在Application.Run中的,我等于重写了Application.Run
    估计这个消息会失效