Jump to content

Preserve Run-Time Class - What should I expect when casting a parent to a child?


Recommended Posts

I'm using the preserve run time class function to cast an incoming object like this.

When I pass a parent class object into the EventMessage in, the current value of the parent class property is not preserved on the output. When I pass in a child class, the parent property is preserved. It's like a new default instance of the child class is created when I pass in the parent rather than a child class instance that has the incoming parent's properties preserved and defaults for the undefined child class properties. I expected the preserve run time class function to take the instance of the parent and "deep-copy" it a new child instance if the parent was on the wire. Apparently, I'm wrong about that. But I have to ask why this behavior? I can't think of why one wouldn't want to preserve the parent's properties as part of a cast (it seems that's a safe cast, like casting a 16 bit int to a 32). What am I missing?

Thanks,

Mark

post-1322-0-39539300-1315923258_thumb.pn

Link to comment

The PRTC primitive does not cast a parent to a child. It takes an existing child which is traveling on a parent wire and outputs it as a child wire. If the data in the left input is NOT a child, the primitive should return an error (and, as you've seen, a default child).

Link to comment

Yair,

Thanks for the info - so I'm expecting more from the function that it's designed to do - I guess the function name explains it if I read carefully :). Still, would it be useful to have a function that could convert (actually deep copy) a parent to a child and preserve the parent's data since it seems that would always be a safe thing to do? As far as I can tell, the To More Specific class VI would do the same thing as the Preserve Run Time Class - that is, fail and return a default instance of the child.

Thanks,

Mark

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
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.