[Lazarus] Enqueuing a callback from a thread via other class - or am I overcomplicating this ?
José Mejuto
joshyfun at gmail.com
Mon Jun 19 01:30:51 CEST 2017
El 18/06/2017 a las 22:44, el es via Lazarus escribió:
> Hence the object, would have to have ITS callback routine be something
> like a TNotifyEvent ( procedure(AObject: TSomeObject) of object, or
> something), and the flag set is set when the callback returns to the
> object context like
>
> procedure TSomeObject.Callback;
> // this procedure is enQueue()d by the thread
> begin
> if Assigned({Self.}FSomeObjectNotifyEvent) then
> FSomeObjectNotifyEvent(Self);
Hello,
Just exit the procedure and there is not free problem. You will get an
exception when you use object data, not object code.
procedure TSomeObject.Callback;
// this procedure is enQueue()d by the thread
begin
if Assigned({Self.}FSomeObjectNotifyEvent) then
FSomeObjectNotifyEvent(Self);
Self.CanBeDestroyed := true;
Exit;
end;
After you set CanBeDestroyed to true you must consider all data as
RANDOM, so don't access any property or variable.
Remember that creating and destroying threads is very expensive in CPU time.
--
More information about the Lazarus
mailing list