By the way: 

I see that you put the creation of the Thread in the OnTimer Event; so an 
instance of the 
thread object is created (and a thread is started and killed) every time the 
timer fires. 

I was wondering how much resources this takes. Isn't it better to have a thread 
property 
in a subclass of a timer, which will be started as soon as the timer is 
enabled? In this 
case, there is 1 thread associated with the timer, and it will never be stopped 
and 
restarted, and everytime when OnTimer fires, it will be executed in this single 
timer 
thread.  

I was wondering which approach is better. Would there be any difference in 
resources it 
takes? 

Rinke



On 6 Sep 2005 at 14:18, Cosmin Prund wrote:

> How about a timer that creates a new thread object from it's OnTimer event? 
> All you need to do is drop a standard timer on your form and create your 
> thread object from it's OnTimer event, something like this:
> 
> <code>
> procedrue Form1.OnTimer(Sender:TObject);
> var Thread:TMyThread;
> begin
>   Thread := TMyThread.Create(True);
>   Thread.FreeOnTerminate := True;
>   Thread.Resume;
> end;
> </code>
> 
> Writing the code for TMyThread is not that hard:
> 
> <code>
> type
>   TMyThread = class(TThread)
>   public
>     procedure Execute;override;
>   end;
> 
> procedure TMyThread.Execute;
> begin
>   // Your code goes here!
> end;
> </code>
> 

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to