Ton Plomp Posted April 17, 2013 Report Share Posted April 17, 2013 I am trying to determine whether a class will override a specific method before running the override. I am coming up with the following code: Is this the preferred method? An alternative (probably faster) would be: Ton Quote Link to comment
mje Posted April 17, 2013 Report Share Posted April 17, 2013 Is this in a scripting context? The code you have makes a few assumptions, namely that the class is in the same folder as its VIs, and that all the classes aren't qualified by library names. Quote Link to comment
Ton Plomp Posted April 17, 2013 Author Report Share Posted April 17, 2013 No it's not about scripting. I want to create a plugin class hierarchy and have a generic config GUI. If a class overrides a specific method I will enable a button that allows to open a class specific config GUI. I don't think I make the assumption of the path relationship between the method and the class. Ton Quote Link to comment
mje Posted April 17, 2013 Report Share Posted April 17, 2013 Ah right, there's no path assumption. I still think a class qualified with a library name would cause issue though? Maybe using a traditional dynamic dispatch method to query the class to see if it supports the option? Quote Link to comment
Ton Plomp Posted April 17, 2013 Author Report Share Posted April 17, 2013 I can use the OpenG function 'Class name' to find the qualified name of the class. Since I will run this on the default value it will most likely not cost a lot of resources. Questioning the class via a method is a maintenance nightmare for the class creator. Ton Quote Link to comment
Yair Posted April 18, 2013 Report Share Posted April 18, 2013 This could return a false positive if you run it on a class which doesn't inherit from your base class and has a VI with the same name, but I'm assuming you won't do that. 1 Quote Link to comment
Ton Plomp Posted April 18, 2013 Author Report Share Posted April 18, 2013 Thanks for the pitfall warning. Ton Thanks for the pitfall warning. Ton Quote Link to comment
shoneill Posted April 18, 2013 Report Share Posted April 18, 2013 Dunno, sounds like somethings a bit awry with your object hierarchy if you need to be manually checking for overrides..... Havie you tried handing off the UI to the actual class? That way they can automatically show the correct GUI. Hint: Subpanels. Shane. Quote Link to comment
Yair Posted April 18, 2013 Report Share Posted April 18, 2013 And speaking on that specific topic, there were some discussions on this before. Here's one example - http://forums.ni.com/t5/LabVIEW/An-experiment-in-creating-compositable-user-interfaces-for/m-p/1262378#M529154 Quote Link to comment
MikaelH Posted April 19, 2013 Report Share Posted April 19, 2013 Just Create a method called "HasGUI" and let anybody override it and return True, if they want you to call it. Quote Link to comment
drjdpowell Posted April 19, 2013 Report Share Posted April 19, 2013 I want to create a plugin class hierarchy and have a generic config GUI. If a class overrides a specific method I will enable a button that allows to open a class specific config GUI. Would it be better to have a “ConfigGUI” object that was recursive (contained an optional subConfigGUI)? Have a “Get ConfigGUI” method that has a “subConfigGUI” input. The parent implementation would initialize the generic GUI and add the inputted subConfig GUI. Child implementations could override the method to initialize a specific GUI and pass this in to the parent method. The “display” (or whatever) method of the ConfigGUI object would enable the button if a non-default subConfigGUI was present. That avoids any class introspection. It would also work at any depth (so your more specific GUIs could themselves have even more specific sub-GUIs). Quote Link to comment
Aristos Queue Posted April 19, 2013 Report Share Posted April 19, 2013 How about giving the class a method called "Get Editor GUI" that returns a VI refnum, and if it returns Not A Refnum then it has no special GUI and if it returns a refnum then you run that GUI? In other words, instead of overriding the editor VI directly, override the accessor VI for that GUI. 1 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.