whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

34 Visitors Online


 
...execute actions when the program is Idle?
Autor: Andreas Rumsch
Homepage: http://www.ardesign.ch
[ Print tip ]  

Tip Rating (7):  
     


unit Unit1;

interface

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

type
  
TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    
{ Private-Deklarationen }
  
public
    
{ Public-Deklarationen }
    
procedure MyIdleHandler(Sender: TObject; var done: Boolean);
  end;

var
  
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.MyIdleHandler(Sender: TObject; var done: Boolean);
begin
  
// do something here
  // hier irgendwas tun
  
Self.Left  := Random(Screen.Width - Self.Width);
  Self.Top   := Random(Screen.Height - Self.Height);
  Edit1.Text := TimeToStr(now);
end;

procedure TForm1.Button1Click(Sender: TObject);
var 
  
dt, dtn: TDateTime;
begin
  
// simulate heavy calculatin with this button
  // umfangreiche Berechnungen simulieren
  
dt := Now;
  repeat
    
dtn := Now;
  until dtn > (dt + 10 / 3600 / 24);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  
// assign the Handler to OnIdle of the Application
  // den Handler dem OnIdle von Application zuweisen
  
Application.OnIdle := MyIdleHandler;
end;

end.


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners