I encountered a strange problem with Delphi on Win64 only.
typedefs:
type
TResolveResponse = record
isResolved : Boolean;
value : String;
end;
TValueProvider = function (const Key : String) : TResolveResponse of object;
TValueProviderProc = function (const ptr : Pointer; const Key : String) :TResolveResponse);
[...]
// helper method
function MakeValueProvider(proc : TValueProviderProc) : TValueProvider;
begin
TMethod(result).data := nil;
TMethod(result).code := @proc;
end;
I’m calling a list of TValueProvider functions until one of them returns with “isResolved = true”. (The TValueProviderProc allows to cast a function to a class function and I think you have seen this a thousand times already.)
On Win32 the compiler allocates the TResolveResponse record structure and assigns it to the local Result variable of the class function. However, when switching to Win64, the Result variable is “inaccessible” for a reason that’s not obvious (to me) and raises a GPF on access.
I have worked around the problem by redefining TValueProvider to procedure (const Key: String; Result: PResolveResponse) of object;
thus providing a preallocated return structure but the problem is somehow burning inside of my mind 😉
I expected the Result variable in my TValueProvider functions not to be “inaccessible.”