06-24-2009 10:04 AM
06-24-2009 10:19 AM
Please edit the icons (good leason to learn what part comes from the class and what part are VI specific) and post some screen shots with a short narative please. I am on-site with an old version of LV and can't do so myself.
Your reply with those screen shots will be agood intro for others and it will let us check your understanding (as well as me learn from others that know LVOOP better than me).
Trying to learn as a team,
06-24-2009 10:25 AM
Sure, I will try to get some screen shots up.
Quick question : I tried to create a new class. I put 3 controls in the cluster for the newly created class.
When I created a new VI, I tried to unbundle the class to access the elements, but I got an error saying the class was 'private'.
Am I doing something incorrectly?
06-24-2009 10:33 AM
The Unbundle by name etc can only be used by a VI that is a member of the class. Right click on the class and choose "create accessor". THis will give you a dialog that will then create the accessors for you. Use the accessors to put dat in and get data out.
06-24-2009 10:58 AM
Here is my understanding of Bens code. Take it with a grain of salt.... or rather, the amount of salt on McDonald's french fries.
On the top level VI, named Test.vi, you can 'add' A and B.
The index will tell the VI whether to treat A and B as an instance of the 'data' class or an instance of the 'strings' class.
Both classes are clusters of 3 controls : A, B, and Answer
For example, if you enter A = 8 and B = 9:
If you set the index to 0, both A and B will be treated as numbers.
If you set the index to 1, A and B will be treated as strings, so 'adding' them will concatenate.
In the code for Test.VI, you can see that first the two class constants (data and string) are built to an array.
The index then chooses which class to operate with.
The next 2 functions create an instance of A and an instance of B respectively as the selected class.
Once A and B are defined as objects of the selected class, they are 'added'.
The 'Add' VI first figures out what class the objects are in, then adds them accordingly.
If it determines that A and B are numbers (instances of 'data') it will add the two values:
If it determines that A and B are instances of the class 'strings' it will concatenate:
In both cases, the returned value is passed to the control 'answer'.
This answer is read by 'Read Answer.vi':
The user then sees the final answer of the whole operation.
I hope I didnt butcher that explination too much.
Feel free to explain further if you feel I left anything out.
06-24-2009 11:05 AM
This is starting to look more like a "nugget".
06-24-2009 11:25 AM
Let me split hairs.
Only the parent class "Data" has anything in its private data cluster. The other two classes do not have their own data, they inherit the data from their parent.
THe two child classes Numeric and Strings only have a single VI each. THey have their own version of the "add" VI (method) that is used to over-ride the callers version of "add" when it comes to execute that function. Which type is used is determined by which class it was passed.
Thank you Cory!
06-24-2009 04:14 PM
06-24-2009 08:31 PM
Cory K wrote:
Ben, for your 'add' VI in the top level VI, how did you import the other 2 add VIs so it knew to only select from among those 2?
After creating the dummy add in the top level class and defing the child classes I,
Right-click (in proj window) on child class and select Create Vi for over-ride.
That will give you a dialog window to choose which VI you want to over-ride (any of the ancestors VI with dynamic dispatch connectors (I think).
Repeat for the other class or "Copy Save as" on one class to clone it and then mod the over-ride VI for the other class.
If you right-click the class and choose properties you can define your inheritance to control which classes that class inherit from.
I use the over-ride all of the time to define my class names. In the "Create_New" methods (OOP talk for creating a new instance, ie "Init" ) an over-ride VI calls its parents "Read Class Name" property (Cludge that is helping my until I learn a better way) and appends its name and writes it back to "Class Name". When read by the child class when executing it reads like a VI call chain, a kind of class chain.
Have fun and keep asking questions. I'm just learning LVOOP myself and thinking about your questions is helping me a lot.
07-01-2009 11:15 AM
I just looked through DFGray's Xylophone project.
That really shows how powerful LVOOP is.