LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LVOOP -- Difference between "Class in" icons on Block diagram

Hello @Everyone,

 

I have recently started learning OOP paradigm implementation in LV.

I noticed that if I dragged a LV class from LV project hierarchy directly on the block diagram of a VI, I was getting a different entity in comparison to what would appear if I dragged it onto the VIs Front panel.

Also, doing it in the first manner, I am not getting any corresponding FP entity.

 

I suspect I might be missing on some fundamental concept here. Kindly guide me.

 

Additional info: I am using LV2020 SP1.

 

PFA, screenshot for reference.

SamKan1_0-1745839942535.png

SamKan1_1-1745839987009.png

 

 

0 Kudos
Message 1 of 6
(327 Views)

Hello Sam,

 

When you drag something on the block diagram it will create a constant (so there will be no terminal on front panel).

When you drag something on the front panel it will create a control.

 

You can redo all this by dragging a string from another VI, to see the differences.

 

A constant cannot be used as a terminal of a VI, whereas a control can.

 

0 Kudos
Message 2 of 6
(316 Views)

Hello @PinguX,

 

Thank you for your response. I was suspecting some foundational concept to be at play. It's clear to me now.
I do have an additional question to this.

What is the usecase of an object constant on the block diagram and, if we can really call it an object constant or a class constant would be more suitable?
I can think of following uses for a class constant:

1. Help in typecasting to a particular class type using "To more specific class" node.

2. Initialize a shift register.

 

The thought process behind this question is, as it's a constant I am assuming it to have default values for each attribute and I also have a reference coming out of it. Does that mean I can call methods on this constant?

0 Kudos
Message 3 of 6
(225 Views)

Remember that LabVIEW classes are by-value so there aren't any constructors. Dropping a class constant is kind of equivalent to creating a class object with all default values so you are able to call methods on that constant.

 

Besides what you mentioned about using class constants for type casting or initializing shift registers, you'll usually have some initialization method for the class which has no class input but does output a class. In the simplest case that method would bundle initialization data into a class object constant.

0 Kudos
Message 4 of 6
(206 Views)

Regrettably, you can even have class constants with non-default values. They get a black border, see here: https://lavag.org/topic/11050-labview-constant-values-change/page/2/#findComment-144406

 

0 Kudos
Message 5 of 6
(198 Views)

One use case for class constants is for factory patterns that you don't need to load dynamically. Plop down a few child classes in your case structure and wire them all to the same output node, and it'll automatically convert to the common parent class.

 

They're also used as inputs when coercing classes (To More Generic Class and To More Specific Class) when handling parent/child classes.

 

Also, you'd use them when defining sets or maps via the block diagram.

 

Also, they're useful as constants in typedefs, clusters, or other object's private data controls.

 

Basically I mainly use constant values to get their type. I don't use class default values too much other than for the factory pattern I mentioned above. Comparing them, non-default values, etc. is tricky since you can't easily tell what a BD constant class has inside itself, so I prefer to do that explicitly if I need to.

0 Kudos
Message 6 of 6
(186 Views)