I have data that is being read in to a RESTful server in the form of name=value pairs.
The server code has a mapping of allowed "name" with a corresponding Delphi type and I wish to convert the "value" part (which is received in string format) to a corresponding TValue variable which is used further along in the processing chain.
Short of setting up a big if/else statement that tests for the mapped type of the "name" is there any way that RTTI can help out. I can get the PTypeInfo of the mapped type using the FindType method of TRTTIContext, and I can see some TValue methods that take a PTypeInfo parameter.
At this stage I've looked at TValue.Cast and TValue.Make but they fail when converting '10' to an Integer.
Do I just go back to the if/else approach and handle the types I need to deal with ?
'10'
isn't an integer. It's a string.TValue
is a variant type. You don't use it to convert between types. – David Heffernan