Registriert seit: 12. Aug 2003
Ort: Soest
4.027 Beiträge
Delphi 10.1 Berlin Enterprise
|
AW: Speicherleck bei der Verwendung von anonymen Methoden
20. Okt 2011, 09:04
Antwort von Barry:
Zitat:
When you assign a regular method to a method reference it is actually identical to writing an anonymous method that wraps the method call:
Delphi-Quellcode:
TFooType = reference to procedure(fooArg: TFooArg);
foo: TFooType;
foo := Self.Bar;
foo := procedure(fooArg: TFooArg)
begin
Self.Bar(fooArg);
end;
This captures 'Self' - so you could theoretically find out the instance to which the method reference is referring to, using RTTI tricks - but you would need to disassemble the code of the anonymous method to get to the method itself. If the method is virtual or dynamic, it will be using a different calling mechanism than if it is non-virtual, and similarly it will be more or less obscured.
|