On Mon, 25 Apr 2022, Thomas Kurz via fpc-pascal wrote:

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.

If it is the last thing you do in the method, there is no problem.

Note that "Free" itself is a method that calls Destroy (the actual
destructor), so the advice you got was strange to say the least :-)


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.Synchronize(NIL, @MyData.Run)

That should work.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to