[Lazarus] TThread.Synchronize from anywhere

Damien Gerard milipili at shikami.org
Sat May 10 17:31:56 CEST 2008


Le May 10, 2008 à 3:06 PM, Luca Olivetti a écrit :

> En/na Damien Gerard ha escrit:
>> Hi !
>>
>> I have to use threads in a GUI app.
>> I have a class which is descendant of TThread and Synchronize is used
>> to update all Visual controls.
>> However most of the functions are not within this class and it is
>> difficult to broadcast the current TThread var.
>
> ???
> You are either calling these functions from a thread (so the thread is
> finally responsible for calling synchronize), or you're calling them
> from the main thread, so there's no need to call synchronize.
> OTOH if these functions are the one uptading the visual control, they
> should be called by the synchronized method, not by a normal function
> method. In any case there's no need for the function to know anything
> about the thread.
> If the functions really need to know the thread, maybe they should be
> defined as methods of the thread or one of their parameters should  
> be a
> TThread.


My thread calls functions to update a sqlite database. These updates  
may require a visual update.
Consequently I have to use Synchronize() to call these functions. So I  
would like to call synchronize only when I have to.
However, I can not add a TThread parameter to all methods.


--
Damien Gerard
milipili at shikami.org

"Intelligence is 10 million rules."
    -- Douglas Lenat









More information about the Lazarus mailing list