Jump to content

Bad type cast error when going to more specific class


Recommended Posts

I have a "listSpec" class which is part of some reuse code which contains properties in a name/value format. In a certain utility I need additional functionality for the listSpec class. So I created an "analyzeSpec" class which inherits from the listSpec class.

In my utility I load a file which creates the listSpec objects(this is the reuse code). I would then like to convert the listSpec objects into analyzeSpec objects to extend their functionality. I need the runtime value of the listSpec objects to be transfered to the analyzeSpec objects.

I tried to use the "to more specific" class function. It compiles correctly, but generates a runtime error stating "LabVIEW: Bad type cast. LabVIEW cannot treat the run-time value of this LabVIEW class as an instance of the given LabVIEW class."

Does anybody know how I can achieve my original goal of generating analyzeSpec objects from listSpec objects while maintaining the runtime value of the original listSpec objects? Or am I in a completely wrong neighborhood and should try a different implementation method????

Link to comment

You have to start by creating the child object (analyzeSpec), but you can then of cause use it as it was a normal listSpec object, but now you have the option to use the childs methods as well.

To be able to convert it from a base to a child in runtime is not allowed, maybe it will be some day.

See Wish List , Post 8-

//Mikael

Link to comment

mane: Here's the post that covers specifically what you're doing:

http://forums.lavag.org/index.php?showtopi...ost&p=34203

QUOTE

To be able to convert it from a base to a child in runtime is not allowed, maybe it will be some day.

No, it won't be allowed someday. As I explained in the other thread, that would be a major violation of encapsulation to provide such a generic casting mechanism. You're free to write such a conversion tool (as shown in the post above) for making children out of parents. But LV (nor any other OO language) will never provide such functionality directly. (Again, see the other thread for details about why.)

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.