11-23-2013 08:36 AM
Hi guys,
i'm searching for the way to create a Class that works the same as for example the notifier.
The vi for creating a new notifier accepts all data types and even changes wire-style of the outcoming notifier reference automatically.
All in all, this behaviour looks very similar to the behaviour of an gerneric class in java...
Is there a possiblity to create this behaviour for my own labview classes?
best regards
g0
11-23-2013 06:55 PM
LabVIEW doesn't currently support generics. Apparently, NI has tried several times (and there actually is code inside LV today which allows it) and each time there were problems with the result.
If you want this to happen, vote for this idea, but don't hold your breath - http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Provide-a-better-way-to-implement-a-polymorphic-VI/idi...
Also, read the comments there for more details.
There are various workarounds, such as using variants or polymorphic VIs, but nothing exactly like what you want.
11-23-2013 08:18 PM
Yes and no (i'm not clear on what you're after), but you can create a polymorph vi which'll be able to accept most any input, or in the case of classes, make all a sub-class of something and use something as input. 🙂
/Y
11-24-2013 04:55 AM
Thank's for your quick answers!
What I'm after:
i want to implement an array list which accepts a key&value pair as input. The thing is that on one hand i need this list to work with string keys and on the other hand i need this list to work with integer keys.
In Java such a problem would be solved by using generics... but I've already heared that generics aren't provided in labview.
The use of the variant type for the key parameter would be a solution. I could create a base class and
in the sub-classes there would be a type cast (variant to data) to check if the type of the key is correct...
The problem of this solution is that an invalid key type is only recognized at runtime...
A better solution would be the use of polymorph vi's...
When i saw the behaviour of the notifier which obviously recognizes every type and therefor even changes it' wire style (and maybe even internal code) i thought that there could be something similar to generics which i can use...
To behonest, I already suspected that one labview is able to do so
I'll again thank you for your answers and I'll have a look at the work-around methods.
If there are any further suggestions don't hesitate to post them...
11-24-2013 03:39 PM
For something as simple as two data types, poly VIs are probably the easiest way to go. If you want to minimize code duplication, you can have one wrap the other (e.g. have the number version convert the number to a string and then call the string version) or have them both wrap a core with the actual functionality.
11-24-2013 04:16 PM
Or you make an array of cluster, containing both an integer and a string, but only 1 is active for each index. 🙂
/Y