04-21-2019 05:21 PM
I noticed the "Variant to Data" function does not work as one could expect when casting VI server refnums.
Indeed, if I have a refnum of a specific class (e.g. Numeric) that I upcast to a generic class (e.g. GObject), then feed it to the function to cast it back to a lower class (e.g. Control), it simply throws an error...
Is it an expected behaviour ? I always thought "Variant to Data" just used the same behaviour as "To More Specific Class" / "To More Generic Class" when dealing with VI server refnums.
The upcasting however works fine...
The reason I am not using these 2 last VIs is because the input data I want to cast can be of any complexity (e.g. clusters that contain refnums AND non-refnum data), and the refnums may have been previously upcast.
04-21-2019 07:42 PM
The error is because a GObject Ref (your input to Variant to Data) is not a Control Ref.
Do it like this:
04-21-2019 09:26 PM
Yes but in this case, "Variant to Data" should be able to convert the GObject to a Control since it IS a Control (and more specifically a Numeric).
As it is, it just seems like this part of the conversion has not been implemented...
And to repeat what I said, I'm searching for a generic solution that could work for data types of any complexity (like nested clusters, arrays, containing refnum and non-refnum data), so using "To More Specific Class" after Variant To Data is not helpful.
Here is a better example to illustrate my needs :
Function1 will always fail as "Variant To Data" cannot downcast the refnums, even if the actual data type of the passed value DOES match.
04-21-2019 10:34 PM
Look at the Data Type Parsing Palette for inspiration.
Here is a simple way to find the kind of reference, it's generic because you made it generic.
You will need to write something to handle all of the possible cases for your cluster.
mcduff
04-22-2019 08:40 AM
@raphschru wrote:
Yes but in this case, "Variant to Data" should be able to convert the GObject to a Control since it IS a Control (and more specifically a Numeric).
As it is, it just seems like this part of the conversion has not been implemented...
And to repeat what I said, I'm searching for a generic solution that could work for data types of any complexity (like nested clusters, arrays, containing refnum and non-refnum data), so using "To More Specific Class" after Variant To Data is not helpful.
Here is a better example to illustrate my needs :
Function1 will always fail as "Variant To Data" cannot downcast the refnums, even if the actual data type of the passed value DOES match.
Be careful what you wish for, you just might get it.
I wrote this Nugget 12 years ago that takes on that task.
I posted code that will write an (semi) arbitrary cluster of any type that includes cluster and arrays (up to 2d) and arrays of clusters of arrays ad nauseum (sp?) to an ini file and restore same.
That was written before all of the functions that McDuff shared. Those were introduced to fill the gaps that I had to fill with my example included in that Nugget. So start with what he shared because doing it the way you are attempting will lead you down the road I described in my old Nugget. If nothing else read over that Nugget and follow-up post to see what you are getting yourself into. (Back in LV 8.2 we had to code using stone knives and bear skins)
If there is newer better way to do, use it!
Ben
04-22-2019 10:47 AM
It seems to me that you should fix the "User Input" part. Your "Function 1" handler is expecting a cluster containing an array of control references,
but your "User Input" is sending an array of generic references. If "Function 1" can only handle an array of control references, you should only send it an array of control references. If you want to send it an array of generic references, you should make the "Function 1" be able to handle generic references. You're putting a square peg inside a cylinder, trying to pound the cylinder into a square hole, then complaining that it doesn't fit.
04-22-2019 11:01 AM
@paul_cardinale wrote:
... You're putting a square peg inside a cylinder, trying to pound the cylinder into a square hole, then complaining that it doesn't fit.
Just use a bigger hammer.
Ben
04-22-2019 11:55 AM
You should be making a cluster of control references (preferably typedef'd) and not an array. That way, you can access each control ref directly, instead of going through such convoluted code.