On 06/08/2011 05:28 PM, Krzysztof wrote:
Hm, I forgot about Application.QueueAsyncCall. And this can be safely
call from thread without TThread.Synchronize() ?
This is exactly what Application.QueueAsyncCall() (and what the
Delphi-Worlkalike TThread.Queue() ) does-
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;
here is the code I tested (the thread class offers a proptery
"OnACall_Parameters" as a hook for attaching a Main-Thread handling
procedure):
------------------------------------------------------------------------
Type
TAsyncData = record
S: String;
D: Integer;
end;
TPAsyncData = ^TAsyncData;
TAsyncCall_Parameters = procedure(S: String; D: Integer) of object;
public
OnACall_Parameters: TAsyncCall_Parameters;
var
PAsyncData: TPAsyncData;
begin
new(PAsyncData);
PAsyncData^.d:=Global_I;
PAsyncData^.S:= 'T E S T';
Application.QueueAsyncCall(@DACall_Parameters, PtrInt(PAsyncData));
end;
procedure TWorkerThread.DACall_Parameters(Data: PtrInt);
var
PAsyncData: TPAsyncData;
begin
PAsyncData:=TPAsyncData(Data);
if assigned(OnACall_Parameters) then
OnACall_Parameters(PAsyncData^.S, PAsyncData^.D);
Dispose(PAsyncData);
end;
------------------------------------------------------------------------
-Michael
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus