Главная страница | назад





Article #21799: How to I allow an application to perform operations while idle?

Question:
How to I allow an application to perform operations while idle?
 
Answer:
By writing an OnIdle event handler.
 

    The following provides sample code for setting up an OnIdle Event:
 

    \\---------------------------------------------------------------------------
    void __fastcall TForm1::FormCreate(TObject *Sender)
   {
        Application->OnIdle = MyIdleHandler;
   }
    \\---------------------------------------------------------------------------
 

    \\---------------------------------------------------------------------------
    void __fastcall TForm1::MyIdleHandler(TObject *Sender, bool &Done)
   {
       \\ Place code to be processed while idle here.

       \\ When true, this event is called only once as the application
       \\ transitions into an idle state.
       \\ When false, this event is continually called.
       \\ Note: Applications that set Done to false consume an inordinate
       \\ amount of CPU time, which affects overall system performance.
       Done = true;
   }
    \\---------------------------------------------------------------------------
 

Finally,  you just need to add the event to the unit header file. It should be added under __published, like so:

    __published:    \\ IDE-managed Components
        void __fastcall MyIdleHandler(TObject *Sender, bool &Done);
 
 

Last Modified: 18-DEC-00