EDIT: The code should be "TThread.ForceQueue", not "TThread.Synchronize"; I have corrected that.
I cannot remember why, but a long time ago when learning Delphi 5 or 6, I have learned not to call the destructor from within any method of the class, only from outside. If this is no longer true nowadays (or maybe, has never been true before), I'd like to use this solution. Just to be sure we're talking about the same thing -- you think this code should work: type TMyData = class method: TMethodWithParameters; a: whatever; procedure Run; end; procedure TMyData.Run; begin method (a); Self.Free; end; ... MyData := TMyData.Create; MyData.a := ...; MyData.method := @SomeMethodWithParameters; TThread.ForceQueue (NIL, @MyData.Run) ----- Original Message ----- From: Michael Van Canneyt via fpc-pascal <fpc-pascal@lists.freepascal.org> To: Thomas Kurz via fpc-pascal <fpc-pascal@lists.freepascal.org> Sent: Monday, April 25, 2022, 16:58:26 Subject: [fpc-pascal] Correct way for using TThread.ForceQueue? On Mon, 25 Apr 2022, Thomas Kurz via fpc-pascal wrote: > This is a very elegant solution but it can only be used for Synchronize, > right? Because with ForceQueue I cannot know when it's done and freeing > within Run (i.e. "Self.Free") would fail. Why would this fail according to you ? I have used this approach on multiple occasions. Michael. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal