LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to create multiple objects within a class

I have a item.lvclass which has an item.ctl (contains a cluster of class private data).  I need to add another object (item2.ctl) within that same class so that I can reuse the code for that class.

 

So how do you create additional objects within the same class?

0 Kudos
Message 1 of 5
(3,558 Views)

Well... right now...  I've cornered myself going down this path:  http://forums.ni.com/t5/LabVIEW-Idea-Exchange/LVOOP-Interfaces/idc-p/1314637#M8918

Seems like the solution in the idea was not implemented yet....

 

 

Okay.  I will try to describe the situation differently...

 

 

Let's say I have a Car.lvclass

 

I want to have two objects:  sedan & roadster

both have similar properties, but also have different properties:

4 doors vs 2 doors

hardtop vs convertible

silver vs white (color)

 

I want the two objects to be of the same class so that they can share the same private and public VI's.  As a matter of fact, I want to have both objects in the VI's within the Car.lvclass.

 

 

 

0 Kudos
Message 2 of 5
(3,555 Views)

Why doesn't standard inheritance work?

 

Make a car class with Dynamic Dispatch Vis for

door count

top type

color

 

make a sedan class that inherits from car and override the Dynamic Dispatch VIs so

door count returns 4

top type retuns hardtop

color returns silver

 

make a roadster class that inherits from car and override the Dynamic Dispatch VIs so

door count returns 2

top type returns convertible

color returns white

 

For this example another option would be to put the door count, top type and color in the private data of the car class then make accessors with the write side having protected access. Then make sedan and roadster constructor vis that fill in the right defaults.

0 Kudos
Message 3 of 5
(3,550 Views)

Actually, I may have poorly described my situation...  I'm still learning LVOOP.

 

After a conversation with a friend, I discovered that I had not called the Create Object VI a second time to instatiate the 2nd object.

I will try that and post if that was the case.

 

Concerning the inheritance, those VI's exist...  I could not get what I though was a 2nd object to inherit from the class because I had created another class intead of another object.... D'Oh! 

0 Kudos
Message 4 of 5
(3,545 Views)

It appears that was the case...  I simply had to create a second object from that same class. 

However, I'm still working on it.  I'll see how it goes..

0 Kudos
Message 5 of 5
(3,513 Views)