Jump to content

Your experience: Class holding instances of its type in its private data?


Recommended Posts

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 by for(imstuck)
Link to comment

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.

Link to comment
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. 

 

post-223-0-63301700-1390495816.jpg

  • Like 1
Link to comment
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?

Link to comment
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.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.