[Lazarus] Application.QueueAsyncCall and checking if object still exists
Krzysztof
dibo20 at wp.pl
Thu Sep 22 17:28:38 CEST 2011
Details. This is only draft:
TMyThread = class(TThread)
protected
procedure Execute; override;
end;
TMyObject = class
private
FHttpThread: TMyThread;
procedure ProgressProc(Data: PtrInt);
end;
TProgressObj = class
Status: String;
Id: Integer;
end;
procedure TMyThread.Execute;
var
i: Integer;
prg: TProgressObj;
begin
for i:=1 to 10 do
begin
prg := TProgressObj.Create;
prg.Status := 'Step ' + inttostr(i);
prg.Id := i;
Application.QueueAsyncCall(MyObj.ProgressProc, prg);
end;
end;
procedure TMyObject.ProgressProc(Data: PtrInt);
var
prg: TProgressObj;
begin
Memo1.Append(prg.Status);
prg.Free;
end;
So, when MyObj is destroyed, Queue list have nonexistent pointer to
ProgressProc
and I must clear it because I created object and don't want memory leaks.
Main problem is: I don't know how to tell thread (which is locked in
QueueAsyncCall critical section), that method pointer which he trying to
post, doesn't exists anymore.
2011/9/22 Michael Schnell <mschnell at lumino.de>
> On 09/22/2011 02:56 PM, Michael Schnell wrote:
>
>>
>>
>> IMHO the better way is to check if the object exists in the main thread
>> when called.
>>
> Obviously you need to use a procedure of some other object (e.g. the thread
> itself) and (if necessary) provide the object i9n question (that might be
> destroyed and NILled) as a parameter.
>
> (BTW if the user programmer does not care for it there is no way to detect
> if an object is destroyed. It would need to be NILled by same.So a library
> function can't check this.)
>
>
> -Michael
>
> --
> ______________________________**_________________
> Lazarus mailing list
> Lazarus at lists.lazarus.**freepascal.org<Lazarus at lists.lazarus.freepascal.org>
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110922/1e945f19/attachment-0003.html>
More information about the Lazarus
mailing list