I'm struggling with a simple piece of code, and even it is simple, I can not find a solution for it. On a part I have an event called like this
OnReadMessageParameter(Self, aName, aTypeInfo, pointer(@aValue), [psIsTValue]);
What is important is aValue parameter which is of type TValue. When this is called aValue.IsObject is true. I've assigned to this event my routine in order to handle the data from it:
.DoOnReadMessageParameter(Sender: TROMessage; const aName: string;
aTypeInfo: PTypeInfo; const DataRef: pointer; Attributes: TParamAttributes);
Now, what my problem is, that I've tried in several ways to convert the DataRef back to a TValue item:
var val: tvalue;
tvalue.Make(@DataRef^,TypeInfo(TValue),val);
or another attempt
val := TValue(@DataRef^);
but the IsObject property is false. It must be something really simple which I'm missing out. Any idea?
Where aValue is a TValue, @aValue is a pointer to the TValue structure, not the value it wraps. A better design would be to make the OnReadMessageParameter event have its DataRef parameter typed to TValue itself, rather than an untyped pointer.
However, if you can't control that, you need to cast DataRef to a pointer to a TValue, then deference it -
type
PValue = ^TValue;
var
val: TValue;
begin
val := PValue(DataRef)^;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With