[Lazarus] How to PostMessage to object?

Krzysztof dibo20 at wp.pl
Wed Jun 8 18:48:27 CEST 2011


Ok, this can be done with critical section but what with AV scenario?
Example:
1. Thread add queue calling Application.QueueAsyncCall(MyObj.EventMethod,
0);
2. MyObj is destroyed by main thread
3. Main thread process messages and try call queue added by thread but
reference to MyObj.EventMethod was destroyed by previous message loop. This
cause Access Violation.

I could remove this queue in MyObj destructor but TApplication.FAsyncCall is
in private section :/

2011/6/8 Henry Vermaak <henry.vermaak at gmail.com>

> On 08/06/11 16:28, Krzysztof wrote:
>
>> Hm, I forgot about Application.QueueAsyncCall. And this can be safely
>> call from thread without TThread.Synchronize() ? Because I don't want
>> use Synchronize() in any part of thread code. So this is correct code? :
>>
>> procedure TMyThread.Execute;
>> begin
>>   // <some code here>
>>   Application.QueueAsyncCall(@SomeObj.TestMethod, PtrInt(NewStr('Some
>> value')));
>>   // <some code here>
>> end;
>>
>> There is no chance for deadlock with main thread calling this from
>> inside another thread?
>>
>
> You have to protect it with a critical section (if you have more than one
> thread calling QueueAsyncCall).
>
> Henry
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110608/2d4254bd/attachment-0003.html>


More information about the Lazarus mailing list