01-12-2009 08:55 AM
I spent quite some time trying to figure out the relation between custom controls and object oriented programming. However, it still isn't quite clear to me.
What I want to do:
I want to have a custom control, and hide it's inner workings from the rest of the blockdiagram, so I don't have to wire for every similar object. Not only because I'm lazy , but also to keep the diagram clean and prevent errors.
for instance a graph, a numeric factor and a button.
when the button is pressed the x scale should be changed depending on the factor.
So, this looks like a job for object oriented programming to me. Once I've created something that can do this, I can use it throughout my program. The code that redraws the figure when the button is pressed should be part of the object, so I don't have to connect extra wires and add a value change event when I add a new graph.
Is this possible at all? I tried, but haven't quite figured this out yet. I have to admit I'm pretty new to OO programming and making custom controls. I've been using typedef'ed clusters for most my code so far, which works fine. But it's still a stupid cluster, the only way to have it do anything at all is from the block diagram in the VI you use it in.
The only thing I could come up with so far is add an "event handler" SubVI that does this, and have it accept a reference or local variable to an object. Then, this SubVI and the variable or reference can be put in parallel with the other stuff in the main program loop. But surely there's a better way somewhere?
I don't think I can solve this problem of defining custom front panel objects and methods for it to interact with the objects it represents without help. I keep getting the feeling I must have missed it somewhere. Any pointers will be appreciated.
Thanks!
Jacco.
Solved! Go to Solution.
01-12-2009 09:01 AM
Hi Jacco,
LVOOP provides functions for encapsulating data and providing public and private methods for accessing the encapsulated data. I don't think LVOOP is what you are looking for.
Search the LV examples for "XControl". There is a built-in example which is a thermometer that will display in either C or F degrees. The conversion code is built into the XControl.
So take a look at that example.
Just trying to help,
Ben
01-12-2009 10:05 AM
Jacco K wrote:What I want to do:
I want to have a custom control, and hide it's inner workings from the rest of the blockdiagram, so I don't have to wire for every similar object. Not only because I'm lazy
, but also to keep the diagram clean and prevent errors.
...
The only thing I could come up with so far is add an "event handler" SubVI that does this, and have it accept a reference or local variable to an object. Then, this SubVI and the variable or reference can be put in parallel with the other stuff in the main program loop. But surely there's a better way somewhere?
Thanks!
Jacco.
Hi Jacco,
These two things are exactly what Xcontrols are, a basic VI with a front panel that has an event structure (the facade VI).
If you have any questions I am happy to guide you.
Ton
01-12-2009 10:18 AM - edited 01-12-2009 10:19 AM
TonP wrote:...If you have any questions I am happy to guide you.
Ton
We really need a "Mega-Kudos" button for posts like that!
Ben
01-13-2009 01:22 AM
Thanks you guys, the Xcontrol seems to be exactly what I need.
I tried marking both your posts as solutions, but I suppose it's like Highlander: "There can be only one"
06-08-2009 01:30 AM
I know this has already been solved, but I think this is a good addition to the topic, for anyone else that may fall in here:
http://www.youtube.com/watch?v=pomEr5vQpxM
Though in my case it became more work because then I needed to do all those special "bundle" and "unbundle" VIs for the private data.