Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-12

How to destroy object / component by itself?

5 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Anthony Walter
to Krzysztof
procedure TForm1.FormCreate(Sender: TObject);
begin
  FRecycleBin := TObjectList.Create(True);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
  FRecycleBin.Free;
end;
procedure TForm1.ApplicationProperties1Idle(Sender: TObject; var Done:
Boolean);
begin
  FRecycleBin.Clear;
  Done := True;
end;

...
FRecycleBin.Add(SomethingToJunkLater);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151203/0ef71300/attachment.html>

Reply by email

Michael Schnell
to Krzysztof: How to destroy object or component in its own method (do this in next message queue)?…
Krzysztof wrote
How to destroy object or component in its own method

You can do a "pseudo-finalizer" method in an object that just ends by "Free;".

Here you (e.g. ion a thread) can create an object and queue that function via TThread.Queue, TThread.Synchronize, or Application.QueueAsyncCall. Now the object is automatically freed without you needing to bother about saving it (i.e. a pointer to same) in a variable.

(AFAIK implementing "real" finalizer methods - supposedly just syntax candy for exactly this) has already been discussed in the FPC developers message list)

-Michael

Reply by email