20. november 2002 - 23:01Der er
4 kommentarer og 1 løsning
Application.OnIdle
Er ved at konvertere en exe til en dll. Har en OnIdle event handler kaldet Idle. Som sidste ting i mit Form Create event kaldes Application.OnIdle := Idle; Meningen er, at når applikationen har tid, skal den gentagne et vindue. Eventet bliver bare aldrig kaldt, med mindre en dialog boks er aktiv, f.eks ShowMessage. Hvorfor bliver eventet ikke aktiveret i dll'en, når den bliver det i præcis den samme kode som exe fil. I Idle bliver Done sat til false.
(********************************************* Changing the Enabled property calls either Start or Stop protected methods. *********************************************) procedure TThreadTimer.setEnabled( b: boolean ); begin if b then Start else Stop; FEnabled := bRunning; end;
(********************************************* Starting the timer creates an instance of TTimerThread and launches the thread. *********************************************) procedure TThreadTimer.Start; begin if bRunning then Exit; bStop := false; if not (csDesigning in ComponentState) then begin with TTimerThread.CreateTimerThread( self ) do begin Priority := FPriority; Resume; end; end; bRunning := true; end;
(********************************************* Stopping the timer just sets the stop flag to true, the TTimerThread's Execute method will then end and the thread will be destroyed. *********************************************) procedure TThreadTimer.Stop; begin bStop := true; bRunning := false; end;
(********************************************* Execute method for the spawned thread. Just repeats while the timer is enabled, and calls the timer object's OnTimer event. *********************************************) procedure TTimerThread.Execute; var SleepTime, Last: integer; begin while not tt.bStop do begin Last := timeGetTime; Synchronize( DoExecute ); SleepTime := tt.FInterval - ( timeGetTime - Last ); if SleepTime < 10 then SleepTime := 10; sleep( SleepTime ); end; end;
(********************************************* This method is called within the TTimerThread's Execute, using the Synchronize method. This is because we need to call the event handler from the main VCL thread. *********************************************) procedure TTimerThread.DoExecute; begin with tt do begin if Assigned( FOnTimer ) then FOnTimer( tt ); end; end;
procedure Register; begin RegisterComponents( 'system', [TThreadTimer] ); end;
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.