Jump to content

Programatically down casting strict typecast control


Recommended Posts

Say I have a strictly typecast enum that I want to pass into a more generic vi that (for instance) compares a string to the enumeration strings to return the index of said string, and signals if not present.

It would be great if the vi could take in the strictly typecast enum and still be generic enough to use with ANY enumerated type. Will settle for downcast outside of vi.

Thanks

Link to comment

QUOTE (HChandler @ Oct 3 2008, 01:37 PM)

I'm not sure you're getting what I mean (or vice versa)

Here're a couple of vi's that explain what I'm trying to do. Sorry no pictures, my screen capture (printkey 2000) bombed out.

Convert your enumeration to a variant and pass that in. Use the Variant library (vi.lib\Utility\VariantDataType\VariantType.lvlib) functions to get the strings for that enumeration. The specific VI you want is probably GetNumericInfo.

Link to comment

Oh dang!

I guess I should have checked to see if it really worked. Unfortunately I was focusing on another problem. Your example works MUCH better than mine but still requires the input of the vi to be strictly typedef-ed.

What I was really trying to do is have a vi that you could pass any old enum (including strictly typedef), and a string and get the position of the string in the enum ( or an error if not).

What I really would like to know is if it's possible to pass a strict typedef enum into a non-typed enum.

Thanks

Link to comment

Use the Type Cast node to cast your refnum to an int32. Then use the Type Cast node again to cast that int32 to any refnum type you desire.

Warning: After you do this, when you pass the resulting refnum to various functions in LV, you may or may not crash LV. It depends upon the operation. After all, you're giving a function a reference to one thing that is actually a reference to something else. Some work, some don't. Caveat emptor.

Link to comment

QUOTE (HChandler @ Oct 3 2008, 08:37 PM)

Maybe you should have used a better tool :shifty: .

QUOTE (Aristos Queue @ Oct 3 2008, 11:49 PM)

Use the Type Cast node to cast your refnum to an int32. Then use the Type Cast node again to cast that int32 to any refnum type you desire.

Welcome to the dark side, Stephen. All these years around those supersecretprivate hackers must have poisoned your mind.

P.S. Any reason for taking a detour through the int instead of casting directly to the desired class?

Link to comment
QUOTE (Yair @ Oct 4 2008, 01:25 PM)
P.S. Any reason for taking a detour through the int instead of casting directly to the desired class?
Because many of the class refnums will refuse to cast to each other (wires break) in order to prevent exactly this sort of thing from happening by accident. You really have to think about to consciously decide to do this.
Link to comment

QUOTE (ragglefrock @ Oct 6 2008, 12:15 PM)

You can also use the Scan from String primitive to get the index of a particular enum string. This will work with any enum already, so there's no reason to build a generic subVI for it.

This is absolutely true. However the initial question was to get it inside a SubVI.

(But I see your point: Why wrap it up in a subVI if it works with a single drop from a palette? :thumbup: )

Link to comment

I did not know you could do that with scan string. But then I would not have learned so much about living without pointers :thumbup: .

QUOTE (normandinf @ Oct 6 2008, 12:04 PM)

This is absolutely true. However the initial question was to get it inside a SubVI.

(But I see your point: Why wrap it up in a subVI if it works with a single drop from a palette? :thumbup: )

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.