GregFreeman Posted January 23, 2014 Report Share Posted January 23, 2014 (edited) I am curious how others have solved the problem of holding a class of hte same type in its private data. For instance, a window class that needs other windows in its private data. I know how to do it; I would just like to see if we can have a discussion on what people have found to be the best method for handling this and why. You obviously can't have a by ref class in the "more generally accepted sense" of a DVR inside the class's private data. This still results in recursive loading a compile time error. I have seen storing the aggregated object in a variant, or creating a DVR of the object's type and storing it in the private data of a class. Are there any potential benefits or drawbacks to each? Any other methods you have found to work well? Edited January 23, 2014 by for(imstuck) Quote Link to comment
mje Posted January 23, 2014 Report Share Posted January 23, 2014 Just store it as LabVIEW Object (or any other parent). To keep things safe have your accessor methods act on the proper class: the read will use a To More Specific primitive prior to returning the object, and live with the coercion dot in the write (or use To More Generic Class). Doesn't matter if you're by value or by reference, same deal with the exception being you need to be aware of the implicit lock/unlock on the TMS operation. Quote Link to comment
daal Posted January 23, 2014 Report Share Posted January 23, 2014 I am curious how others have solved the problem of holding a class of hte same type in its private data. For instance, a window class that needs other windows in its private data. I know how to do it; I would just like to see if we can have a discussion on what people have found to be the best method for handling this and why. You obviously can't have a by ref class in the "more generally accepted sense" of a DVR inside the class's private data. This still results in recursive loading a compile time error. I have seen storing the aggregated object in a variant, or creating a DVR of the object's type and storing it in the private data of a class. Are there any potential benefits or drawbacks to each? Any other methods you have found to work well? To resolve this problem, I cast the DVR into a U32. So in your private data of your class you will have only a U32 so not anymore recursive loading. To access your data you will need to recast the U32 to DVR. 1 Quote Link to comment
GregFreeman Posted January 23, 2014 Author Report Share Posted January 23, 2014 Just store it as LabVIEW Object (or any other parent). To keep things safe have your accessor methods act on the proper class: the read will use a To More Specific primitive prior to returning the object, and live with the coercion dot in the write (or use To More Generic Class). This works, I can probably just make my own write accessor which has the expected type on the connector pane and coerces to the more generic class within the write method, no? Quote Link to comment
mje Posted January 23, 2014 Report Share Posted January 23, 2014 This works, I can probably just make my own write accessor which has the expected type on the connector pane and coerces to the more generic class within the write method, no? Yes. The coercion would be automatic, the only reason to explicitly do it would be if one wanted to get rid of the coercion dot. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.