06-25-2012 02:33 AM
Hi!
I've been stuck on this littel issue for some time now, maybe I can't see the wood for trees, maybe my intention is utopic
Here is what I want to do: retrieve class default value from an existing *.lvclass (no prob so far), modify it in some sort of configuration programme and then save back the default value to this (or another) *.lvclass file.
The only intended editing is about changing the default value, not more, not less.
I have tried some VI server magic but failed (LabVIEW crashed)
Any suggestions?
Cheers
Oli
Solved! Go to Solution.
06-25-2012 04:38 PM
The similar thing has been discussed here, and the same reasoning should apply for LVOOP as to why dynamically changing the default value is not possible.
http://forums.ni.com/t5/LabVIEW/Programmatically-set-the-default-of-a-control/td-p/1656554
I would implement some sort of a constructor VI which conditionally sets a initial data using case structures. If the initial data should be determined outside of the process, use FILE I/O to read data to initialize with. You can save a class object data into string using "Flaten to String" function and read it back by "Unflatten from String".
Hope it helps 🙂
SK
06-26-2012 01:05 AM
Well, I do understand this issues for controls, but I'm sill struggling to transfer this to the LVOOP issue.
Here's what I used to understand about loading class default values:
I'm able to load a class default value dynamically from disk as long as inheritance is set right (--> PlugIn Architecture).
So lets say I have a parent class A which has two children B1 and B2. So using the Get LV class default value.vi I'm able to load classes dynamically and cast it to class A (To More Generic Class). This way I can also load Class_B1.lvclass and Class_B2.lvclass and use dynamic dispatch.
Now, if B1 and B2 have basically the same class private data (let's say a Boolean) that only differs in default value (true/false) I have a similar case for loading as what I'd like to do for saving.
Having said that: maybe my intention should be be better described as modifying an existing class default value and save it as a new class.
I guess there is a reason why NI did not implement the saving part... just need to understand why
Oli
06-26-2012 04:20 AM
Hello Oli
With some, as you named it: "VI Server magic", it is possible to edit class default data and save it as the same/new class. However, there are at least three major problems:
So before we'll go further, could you explain more thoroughly, why would you want to to that? If you only want to have two classes, that are exactly the same but differ only in some data fields default values, this is absolutely not a good idea and not a good software design. And relying on default values might generally lead you to unexpected behaviour of your program sometime in the future, when you'll decide to change these defaults.
06-26-2012 06:49 AM
The more I'm thinking about this, the more I think you're right.
First of all, I was completely missing the aspect of run time support for what I wanted to do... I tried to get around the usage of some kind of configuration file, but it seems I won't be able to. Anyway, that's life
But... if anyone tries to achieve something similar like me: http://lavag.org/files/file/65-lvclass-api/ is a good hint
Regarding the question for the use case: initially, I wanted to build a model for sth like a test socket, that holds data, like for example test sequence (again here a class), which can be configured quite conveniently by the user.
The goal was to use as much of LVs API as possible.
Ok, let's continue with the config file approach.
Thanks for your help guys!
Oli