How to I allow an application to perform operations while idle?

By: Christopher Moeller

Abstract: Creating an OnIdle event handler
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);
 
 


Server Response from: SC1

 
Copyright© 1994 - 2008 Embarcadero Technologies, Inc. All rights reserved. Contact Us   Site Map   Legal Notices   Privacy Policy   Report Software Piracy