LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Specify variant type in class attribute for a lookup table

Hello,

 

I have started recently to use classes and variant attribute in labview. However I couldn't find a way to describe it properly in the class.

Is it possible to create the variant as an attribute of my class and specify its type from a typedef ?

 

If I use an array, its perfect because I can create my array attribute, and add the control that is described in a typedef into it.

however with variant, I get the empty variant control without any way to specify what is inside if it is created by me (the name is quickly written into the variant control and disapear).

However, I can do it if I add labview controls but not if it is created from a typedef.

 

Is there any way to do it with a control described in typedef ? also, should I describe it like that to be able to use it through "set/get variant attribute" ?

 

Thanks,

 

Yannick

0 Kudos
Message 1 of 13
(2,985 Views)

Sample code please!

Benoit

0 Kudos
Message 2 of 13
(2,961 Views)

I don't really have a code sample, because I couldn't even get started.

However, these screen capture might make this clearer:

 wrong solution, but explains the result I want to acheivewrong solution, but explains the result I want to acheive

my class attribute as I proceeded first : using arrays and name tversion i want to get rid ofversion i want to get rid ofable (terribly inefficient). I want to use a variant and add/get my alarms using "get/set variant attribute"

 

 

 

However, I can't find any way to describe my alarm properly in the class definition. On this picture you can see the control I want to use and the result I want to achieve. However I now know that putting my control into the variant will not have the right effect as it would not be an attribute of my variant.

 

0 Kudos
Message 3 of 13
(2,954 Views)

If you know the type of the variant, it should probably be a class, not a variant. Or a type def'd cluster, but that's kinda pointless when you're doing OO...

 

The hole idea of the variant\variant attributes is that you don't have to know what is in it. If what's in it is restrained somehow, the variant should be wrapped in a class that enforces the restrictions. But then a normal class would make more sense. Good new is that once it's wrapped, the users of the class don't need to care if it's a normal class or a wrapped variant.

0 Kudos
Message 4 of 13
(2,939 Views)

I can make a class, and will do it, I wanted to use my already made typedef for the test.

 

However, the problem remains : I need a lookup table to set and retrieve my objects.

In Java or C++ I would have had a Map<String, Object> as my looking table. but the only equivalent I have found for labview is the variant data-type with set/get attribute.uml.PNG

 

 

But I cannot figure out how to declare it in my class in labview. It would probably work with an empty variant, but would have to check correct entry manually and more importantly it would be just bad programming. Except if Labview doesn't let any choice here to do a decent code ?

 

Although I understand that my type would not be variant anymore 🙂 : I just want a performant lookup table with a precise type :,(

 

0 Kudos
Message 5 of 13
(2,932 Views)

@YannickB wrote:

I can make a class, and will do it, I wanted to use my already made typedef for the test.

 

However, the problem remains : I need a lookup table to set and retrieve my objects.

In Java or C++ I would have had a Map<String, Object> as my looking table. but the only equivalent I have found for labview is the variant data-type with set/get attribute.


You'd make those objects childs of the same parent. Then, you can have an array of those objects. Or a map, for now in the form of a variant attribute.

 


@YannickB wrote:

But I cannot figure out how to declare it in my class in labview. It would probably work with an empty variant, but would have to check correct entry manually 


That's just not possible. You can't check a variant's type at compile time.

 


@YannickB wrote:

 and more importantly it would be just bad programming.


Yes, it would be bad.

 


@YannickB wrote:

Except if Labview doesn't let any choice here to do a decent code ?


Plenty of options, but variant attributes is not one of them.

 


@YannickB wrote:

Although I understand that my type would not be variant anymore 🙂 : I just want a performant lookup table with a precise type :,(


As long as the variant is in the private data of the class, and all VIs guard the types that you put in it, I don't really see a problem.

0 Kudos
Message 6 of 13
(2,908 Views)

wiebe@CARYA wrote:

@YannickB wrote:

I can make a class, and will do it, I wanted to use my already made typedef for the test.

 

However, the problem remains : I need a lookup table to set and retrieve my objects.

In Java or C++ I would have had a Map<String, Object> as my looking table. but the only equivalent I have found for labview is the variant data-type with set/get attribute.


You'd make those objects childs of the same parent. Then, you can have an array of those objects. Or a map, for now in the form of a variant attribute.

 is in the private data of the class, and all VIs guard the types that you put in it, I don't really see a problem.


Yes, I know , it is exactly what I want. but I need to specify what object (the parent object of course, I know the concept). in the description of my older class.

I want Map<String, Object> not Map<String, anything you want you have no possibility to precise and be efficient>


And yes I could guard the type and use the variant, this would work, but would just be terrible and bad programming. I think that any proper programming language should have a possibility for a typed looking table. And any OOP language should have a possibility to express its relationship with other classes properly.

 

 

 

 

0 Kudos
Message 7 of 13
(2,902 Views)

@YannickB wrote:

And yes I could guard the type and use the variant, this would work, but would just be terrible and bad programming.


When wrapped in a dedicated class, it won't be too bad.

 


@YannickB wrote:
 I think that any proper programming language should have a possibility for a typed looking table.

Soon... Can't say too much as betas are under NDA...

 


@YannickB wrote:
And any OOP language should have a possibility to express its relationship with other classes properly.

Not sure what you mean by that. Variants have nothing to do with OO. So that variant (attributes) are not strongly typed (by design, AFAIC) doesn't invalidate the relationships LabVIEW can make with other classes? What class relationships can't be expressed properly?

0 Kudos
Message 8 of 13
(2,882 Views)

I'm not quite sure of what you're trying to achieve, but having your Alarms as attributes is simple enough. You won't be able to see what type they are during coding (as you're basically working with void*) but can control it. 

Set a variant attribute with a Name and the alarm as property, Get the named property and convert via Variant to data, as you always have to do with variants.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 13
(2,875 Views)

thank you for your answer, can't wait for those typed looking tables this would make things right 🙂

 

what I meant with the impossibility to express the relationship is that doing so for classes its not possible to directly link the UML diagram directly without looking deeply into the code.

In the diagram above I have a 0 to many relationship (my looking table). but if you look at the attributes of the Alarms class you won't see this relationship as it is a variant that could hold anything. you need to check everywhere in the code to know what can be inside.

0 Kudos
Message 10 of 13
(2,872 Views)