Hi all, can anyone explain why the code below fails?
type TIDEThemeObserverFunc = reference to procedure(foo: integer);
var fObserverFuncs: TList<TIDEThemeObserverFunc>
function RegisterEventObserver(aObserverFunc: TIDEThemeObserverFunc): Pointer;
begin
fObserverFuncs.Add(aObserverFunc);
Result := @aObserverFunc;
// line below somehow fails
assert(fObserverFuncs.IndexOf(TIDEThemeObserverFunc(Result)) <> -1);
end;
I assumed anonymous methods can simply be casted and used around via pointers but that seems like a wrong assumption. Also, any resources explaining how the anonymous methods are implemented under the hood would be great. TIA.