The problem is that TObject(666)
is not a real object. So long as you use actual object instances, or nil
, then your code works.
The reason for the access violation is that the GetValue
method ends up calling the TValue.Make(Pointer, PTypeInfo, out TValue)
overload which includes this code:
// make a better-educated guess about type-info when we can
case ATypeInfo^.Kind of
tkClass:
if Result.FData.FAsObject <> nil then
Result.FData.FTypeInfo :=
GetClassInfo(TObject(Result.FData.FAsObject).ClassType);
end;
And that code requires the object to be a real object instance. That code is attempting to obtain the class info for the instance. It receives the type info for the property through ATypeInfo
but then attempts to use the actual type info of the specific instance. And because TObject(666)
is not a real object instance, the code results leads to a runtime error.