Quantcast
Channel: NI TestStand topics
Viewing all articles
Browse latest Browse all 6524

Dynamic population of the data. How to do it?

$
0
0
Hi,
 
It will be long story.
 
I'm working on something, which for my own usage, I temporarily named "quasi-inheritance".
 
The aim of it is to populate with different data a bunch of variables of the same custom type. This custom type in general consist of the container which consist of others built-in, custom and standard data types.
 
Of course at this stage the solution is trivial. Ordinary "=" operation will do the job. However, I do want to copy the data which are "not initialised". If the variable is "not initialised" in the instance of my custom type then inherit it from the default container. If the variable is initialised in the instance of my custom type - accept it and do not inherit respective value from the container storing common data.
 
Why I'm doing it?: My bunch of variables is the collection of the test parameter data for group of the products. The structure of the data set for every product - data type -  is the same for every product. The products belong to the same family and they are differ amongst themselves by small details in the value of the data, not in structure of the data. It'd be convenient to store the common data in one place, and make necessary, distinguish for the product modification, when the data set for particular product is instantiated, in the way described in above. Where is value added? Often, the change is common for all family, and it would be very convenient to to make the change to the test parameter in one place rather than make the change in for example twenty places.
 
So, what this "initialisation" means for me in TS in this case?
 
As far as I know in TS I cannot declare the variable without definition. In TS the defaults are empty string for string, nothing for object reference, 0 for a number and false for boolean. Only object reference and string have a "nullable" feature (value Nothing and empty string respectively) which could be used to determine is the object reference or string were filled in with something. However, I cannot do that on the number and boolean.
 
To arm the numeric data type in this "quasi-feature" of being nullable, we can do by determine does the number data type is initialised or not using simple the trick: I'd use a kind of predefined value which I did not expect to appear in real-world measurement system, for example -999. Then, before the copy operation I can compare is the data in the destination equals -999; in case of positive answer, I'd treat this property as uninitialised, ready to override.
 
For boolean this "quasi-inheritance" mechanism doesn't bring any value added; because it is two state property mechanism I'd need to edit the properties which I'd need to change from default.
 
So I could go through my bunch of variables, enumerate all of them checking and comparing the values with the values I assumed represent "not-instantiated" (not modified). At the end of the day I'd have what I wanted: a bunch of dynamically populated variables fitted for every product in the family.
 
However, this solution looks like bit complicated in comparison we could achieve in other languages. In C# the situation would look a bit different as C# supports nullable feature. So, I could declare the type - let say AAA - with NULL value. Then I could create the instance of the data type AAA with default values. Then I could create my bunch of variables by inheriting or constructing with overloaded constructors from the default instance and explicitly changing values I want to be different from. 
 
Questions:
1. Is there any other way/approach I could populate the bunch of variables in the way I've presented which could be similar - in simplicity - as I'd do it in C#?
2. Can I do it in TS in the different way I've described?
3. If yes, what TS API functions it'd be the best to use?
 

Viewing all articles
Browse latest Browse all 6524

Trending Articles