11-15-2013 09:44 AM
I have an array of lvclasses inside an lvlib, as shown below. I'm looking to get the reference to the individual lvclass I need dynamically, at run time.
The goal is to be able to modifiy or add classes to this lvlib without having to change the rest of my code. Particularly, the code snippet that loads the lvclass will be from a built EXE.
How do I dynamically call these lvclasses inside an lvlib?
Solved! Go to Solution.
11-18-2013 04:06 PM
I will look into this to see what I can find. In the meantime, here are a couple documents that may prove useful.
Plug-in Architecture using Packed Project Libraries: https://decibel.ni.com/content/docs/DOC-19176
Creating LabVIEW Classes: http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/creating_classes/
Using Libraries in LabVIEW Projects: http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/project_libraries/
11-18-2013 09:35 PM
This might be interesting for you. Also, searching Factory Pattern in LabVIEW will probably turn up a number of hits.
http://vishots.com/005-visv-labview-class-factory-pattern/
11-19-2013 01:27 AM
Are these classes inherited from a common lvclass? If so Factory Pattern works. If not you need some work to correct it. Usually in Factory Pattern, you create an abstract class with some Dinamic Dispatch VIs first. Then create an child class which overrides the Dinamic Dispatching VIs. To the To More Specific Class node (in the image you provided), you only need ot pass the abstract object constant and pass a path of the child class that you want to use.
As far as Factory Pattern is concerned, whether classes are in lvlib or on its own does not make difference.
11-19-2013 09:09 AM
TailOfGon,
I suppose I didn't specifically mention it, but yes, I do have a parent class that has the classes in the lvlib above override, all dynamic dispatch. So it is a Factory Pattern already, I'm fairly sure. The parent class is in the EXE, while the lvlib is not. Good to hear that I'm on the right track so far.
I think my only issue is what do I put in the path? I'm not sure how to get a path to an lvclass inside an lvlib...
I'll need to read through all the other links in this thread that have been posted, to see if I can find that answer.
11-20-2013 09:09 AM
Glad to hear that you are in the right track. So only thing you need to do is to specify the correct path. I believe there are several ways to do it.
In my previous project, I have built an exe that uses Factory Pattern. In the build specification, I included all the classes to be called dynamically. To make this work, you have to specify the class path using relative path.
My first attempt was to automatically detect the child classes under the project. Automatic detection could be useful to dynamically populate Ring control. But soon I figured that I cannot explore files within exe. Also this was not a good idea because my class hiearchy has several levels and did not want a user to select abstraction layers.
Then I took a different approach. I register concrete class names to a global variable. Place an array of string in a global. Then put the names of the class to be used (make sure to correctly save the Global). The project structure includes the plugin classes under a specific folder such as: <app dir>\plugin\<class name>\<class name>.lvclass The global can be used to populate Ring in the UI. Once you receive a command to instantiate the object of the select type from the Ring, pass the name string to the path above, replacing <class name> with the actual name.
Hope it helps.
12-04-2013 12:45 PM
Ok, so I figured some things out. "Friday_the_13th" your link to the plugin architecture helped, but I was hoping that my setup would be a bit easier.
If the classes are in a regular library (lvlib), then I figured out how to use invoke and property nodes to get the paths for the classes. This worked in development mode, but when I did an EXE build of the code (and the lvlib is outside the EXE), there's an error 1055. After some research, it looks like I need the "Datalogging and Supervisory Control" module... which I don't have. Someone can correct me if I'm wrong.
If the classes are in a PACKED library (lvlibp), then you can use the "Get Exported File Path" function. Unfortunately, I did not have packed libraries created, but I may have to go that route.
I thought this might be helpful for others trying to figure out how to call items inside of libraries dynamically.
04-22-2014 01:47 PM - edited 04-22-2014 01:48 PM
With some help from NI Support, I've discovered that what I'm trying to do isn't available in LabVIEW 2011.
In 2012 and later, there is a property called "OwnedItems[]" that lists everything owned in an LVLIB. This allows me to dynamically link to an LVCLASS inside an LVLIB.
I thought this would be nice for others to see without having to contact NI Support.