Cleaning up child class on parent wire

I have a child class running on a parent wire. The parent class has a reference, and the child class has some additional references. I want to clean these up during shutdown. But, because it is a parent wire, I cannot call my child class's "destroy" method directly. Is the best way to handle this to have destroy.vi be dynamic dispatch, so it will call the child's destroy method via DD, and set "call parent method" to required? This way if the class is a child, it will dynamic dispatch the child's method, but force the programmer to also call the parent method? How have others handled this?
CLA, LabVIEW Versions 2010-2013

for(imstuck) wrote:
Is the best way to handle this to have destroy.vi be dynamic dispatch...?
Yes. That's the whole point of DD.
Note that for cleaning up resources, the order of the cleanup might be important, so either write in such a way that it doesn't matter or document it so that the developer of the child class knows exactly when the parent destroy should be called.
Try to take over the world!

Similar Messages

  • Fastest way to create child class from parent?

    As the subject states, what do you folks find is fastest when creating child classes directly from the parent? (esp. when the parent is in a lvlib) I thought I'd post up and ask because the fastest way I've found to get working takes a few steps.
    Any suggestions ae appreciatized!
    -pat

    Thanks for the quick response Ben!
    Yea, I apologize, in your response I realize my OP was more than vague haha (it hapens when you get used to your own way of doing things I guess huh)- I'm trying to create a child from a parent so that it has all of the methods that the parent has.
    In order to do so I currently have to open and close LV a few times during my current process so that vi's in memory dont get mixed up- Currently I save a copy of the parent class in a sub dir of where it is saved, close out of LV, open the new 'copy of parent.lvclass', save as>>rename 'child class.lvclass', close LV, and open up the project to 'add file', then right click>>properties>>inheritance.
    Is this the only way to do this?
    Thanks again!
    -pat
    p.s. I'm tempted to steal your cell phone sig, hope you dont mind haha good stuff!

  • Executing a child class from parent.

    Hi, well, I have this parent class which I need to execute a method from a child class to get a significant part of the thing get started. Is there anyway for me to accomplish this or a workabout? Thanks..

    Sure.. I have this method in the class logic:
         public void createLocation() {
              try {
              classCoord coordSet = appinterface.decodeFile();
              int areaNum = coordSet.areaNum, cellNum = coordSet.cellNum, signalStrength = coordSet.signalStrength, receiverId = coordSet.receiverId;
              String dateTime = coordSet.dateTime, userName = coordSet.userName, location = calLocation(areaNum, cellNum);
              boolean validity=calValidity(signalStrength);
              classLocation locationObj = new classLocation(this.type, userName, receiverId, validity, location, dateTime);
              appinterface storeLocationObj = new appinterface();
              storeLocationObj.storeLocation(locationObj);
              catch (IOException ioException) {
                   appinterface.displayMessage("Logic Error: " + ioException);
              catch (ClassNotFoundException classNotFoundException) {
                   appinterface.displayMessage("Logic Error: " + classNotFoundException);
         }I need to execute this method halfway in the class appinterface, the logic class inherits from appinterface cuz I need to make use several methods from it. Is there any way to solve this somehow?

  • How to listen to user actions in child class from parent class?

    Hi,
    I have a basic custom class ChildCustomForm that include a JTextField. In order to know what user types, I add a listener to
    this textbox:
    textField.addKeyListener( new KeyAdapter()
                @Override
                public void keyPressed( final KeyEvent e )
                    //user typed something
                    userTyped = true;
             });Now I have another parent class that uses ChildCustomForm, and parent class has to know once user types, then set
    its own userTyped flag.
    My problem is: since I added listener in child class, I cannot get textfield and add listener again in parent class, so parent class will not be able to know as soon as user types (polling is not a good solution here).
    I am wondering if there is a way to do this?
    regards,

    jack_wns wrote:
    I have a basic custom class ChildCustomForm that include a JTextField. In order to know what user types, I add a listener to
    this textbox:You want to listen for input into the textbox, correct? This may take the form of keyboard input, or could be a paste-text event in which case your keylistener will miss it. I recommend that you look into a DocumentListener here so you will catch any changes, be they keyboard or cut or paste.
    My problem is: since I added listener in child class, I cannot get textfield and add listener again in parent class, so parent class will not be able to know as soon as user types (polling is not a good solution here).The observer pattern may work here.

  • Copy multiple dispatch vi to new child class

    Hi, I have just started with LVOOP and while I'm pretty sure I have a good understanding of the overall theme, there is one problem I foresee if I continue.
    Situation:
    BoardType is parent of classes CC2600 and CC1300. Currently the child classes are just empty place holders.
    Almost all the methods in the child classes will be of dynamic dispatch type (currently only one).
    From what I understand a dynamic dispatch must be available in all child classes plus parent class in order to work as intended. 
    Problem:
    If I would go forward and implementing LVOOP this would require approx 30 dynamic dispatch vis for each class. I can right click but for just these two children that's 60 + 30 vis I must create manually. I would much prefer just to create a template once and then just basically drag and drop 30+ new vis for each new class that is created.
    Is there a way I can define a set of template dispatch vis in the parent BoardType and have them added to all the child classes? 
    I tried the save as copy, but the problem is that I still have to replace the connector pane to represent the new owning class.
    If it helps here's a very basic block diagram of what's going to happen, just after Reset.vi there will be a lot of other dynamic dispatch vis.
    Thanks in advance.
    Michael

    From the OP it sounded like you were literally just copying from the parent.
    What I tend to do is finish one child class and then save a copy to a new name and change the internal data (if required) and DD vis (if required).
    I do agree though that these kinds of operations could be hugely simplified using helper programs.  Give the link provided by others a try.
    Shane.
    Say hello to my little friend.
    RFC 2323 FHE-Compliant

  • Seemingly unpredictable results when calling an overriden parent method on an instance of a child class casted to the parent class

    I have a parent class with a sub-vi Override.vi, and a child which overrides this sub-vi.  I create an instance of this child.  I cast this child to it's parent class and store it in an array.  Later, if I invoke the parent's 'Override.vi' on this child (casted to parent) then Labview 2013 seems to randomly choose whether to run the parent or the child override.vi.  In Labview 2011 SP1 it would always call the childs version of override.vi (which while surprising to me was very useful).  This has totally broken an application I have been developing, any insight as to how to control which override.vi is run would be helpful (re-casting to the child class isn't really an option, as there are in fact many child classes each with their own version of override.vi).

    The actual data type of the wire is irrelevant in deciding which VI to run. The only thing that is relevant is the class of the object which is actually on the wire, so casting to the parent should not be relevant. *IF* the object really is a child, then LV should always call the child's VI, just like you say it works in 2011.
    I suspect that what's happening in your case is that somewhere you're generating a parent and that's what's actually on the wire (e.g. maybe you have an error somewhere and a function outputs the default value, which is a parent). The fact that it didn't happen in 2011 doesn't mean it's a bug in 2013. It could be that something else has changed.
    In any case, it's impossible to tell whether this is a misunderstanding, a bug in your code or a bug in LV without actual code. If you can post actual code which shows this, people can help. Otherwise (if it only happens in code you don't want to publish), you should try contacting NI directly so that you can at least show them the code.
    Try to take over the world!

  • Parent/child classes vs badi or something else

    Dear Experts,
    I’m looking for some architectural suggestions here on the best way to implement “user exits” with classes.
    Up to now, I have coded my software similar to the SAPMV45A method of having an include with subroutines USEREXIT_BEFORE_HEADER and the like.
    It works okay except that the code doesn’t do a great job of encapsulation.  All data has to be global and that gets to be a pain for cleanup.
    I’m wondering the best way to do this as I am not an expert at all in object oriented development.  I've only implemented BADI on a couple of occasions, found it confusing and were it not for tutorials, I wouldn't have been able to do it at all.
    For example, a common flow of my RFC goes like this:
    Perform userexit_initialize in program (sy-repid) if found.
    Perform initialize.
    Perform read_header
    Perform read_items
    Perform populate_header_output
    Perform populate_item_output
    In each of the FORM routines, I have a userexit at the end to allow custom filters or database reads as necessary.
    For example:
    Form read_header
      Select * from header_tab ….
      PERFORM userexit_read_header_finished in program (sy-repid) if found.
    Endform.
    I had hoped I could have two classes, a parent or “core” class to which I can implement only child methods as needed.
    Therefore, it would be more along the lines of:
    Function z_my_rfc
      Importing i_docnum
      Exporting e_header
                     Et_items
                    Et_bapiret2
    Call zcl_core->read_header
    Call zcl_core->read_items
    Call zcl_core->populate_header
    Call zcl_core->populate_items
    What I haven’t really been able to figure out is if I can create and distribute another class zcl_child which I can then customize at every implementation by simply adding a new method and using “super” to incorporate the logic of the zcl_core class.
    I think I’ve seen that this can be done in local class development ( in an include abap program ) but I want to do this in actual classes via SE24.
    Now, my other thought is that this is what BADI are for??
    Periodically, I want to send my customers a transport with update ZCL_CORE class code/methods, etc. but I want to leave the ZCL_CHILD class alone.
    Hopefully, I’ve conveyed my desire here and perhaps you can suggest the simplest way to support this software going forward.
    Thanks in advance for your time and consideration.

    Hi Ray,
    Go for custom BADIs in this case. In fact, that is exactly the functionality you are looking for !
    Just go through this excellent five part blog on Enhancement framework by Thomas Weiss.
    What the New Enhancement Framework Is For – Its Basic Structure and Elements For Beginners
    The new Enhancement Framework Part 2 - What Else You Need to Know Before Building an Enhancement
    How To Define a New BAdI Within the Enhancement Framework - Part 3 of the Series
    How to implement a BAdI And How to Use a Filter - Part 4 of the Series on the New Enhancement Framework
    Source Code Enhancements - Part 5 of the Series on the New Enhancement Framework
    Cheers,
    Mahesh

  • Casting parent class to a child class

    Hi,
    I have a static method which returns a class called parent. Now I want to cast it it's child class. There are no compilation errors, but at runtime it's throwing me ClassCastException. This is what I'm doing.
    public Parent getObject() {
    Parent p = new Parent();
    return p;
    Child c = (Child) getObject();What is wrong with this code? I couldn't figure it out.
    Any help will be appreciated.
    Thanks,

    Parent p1 = new Parent(); // 1
    Parent p2 = new Child(); // 2
    Child c1 = new Parent(); // 3
    Child c2 = new Child(); // 4
    Parent p1 = (Parent)c1; // 5
    Parnet p2 = (Parent)c2; // 6
    Child c3 = (Child)p1; // 7
    Child c4 = (Child)p2; // 81: Ok.
    2: Ok. Every Child IS-A parent.
    3: Compile time error. A Parent object is not a Child.
    4: Ok.
    5: Ok, because every Child IS-A parent, and the cast is unnecessary. (Though since 3 is illegal a compile time we wouldn't actually have this situation.)
    6: Ok, and the cast is unnecessary, because every Child IS-A Parent.
    7: ClassCastException at runtime. The object is not a Child.
    8: Ok.

  • Parent class not waiting for child class to finish

    hi,
    i have class a and method x in class a which calls class b. its fine till there. but before my class b's action is completed, in which i have to choose a file and display those files in jtable, the remaining lines in method x getting executed. what do you think the problem is.
    i.e. my parent's class method is completely getting executed before the child class (frame) returns the result and is closed. where do u think the problem.
    please help.

    i dont know if i made myself clear. i am giving my code below.
    class A{
    btnClick{
    pnlProductsImport _pnlProductsImport=new  pnlProductsImport(dataSource,config,parent,importFile);
    _pnlProductsImport.setVisible(true);
    _pnlProductsImport.show();
    getProducts()
    here its showing my pnlProductsImport class screen and before I close that screen, getProducts method is getting executed. as I know, the control passes from class A to pnlProductsImport at show() and when its closed, it will execute remaning lines i.e getProducts, but in this case, it shows the subclass, and immedietly, executing remaining lines. but its also fact that my subclass (pnlProductsImport) implements Runnable, but thread starts only after some time when I click on one of the buttons on the screen.... and i want that getProducts() method to execute only when subclass closes completely.
    thanks

  • Inheritance problem with parent class calling child class

    I have a problem with inheritance with a parent class calling a child class method. Below is the example pseudocode code and my problem:
    public abstract class A {
        protected void function1 ( ) { }
        protected void function2 () {
             //calls function1();
             function1();
    public abstract class B extends A {
        protected void function1 ()  {
             // do stuff
    public class C extends B {
        protected void function1 ()  {
            // do stuff
            super.function1 ();
    }I have an object instance of class C created and its function2() is invoked.
    My problem is, while in function2(), which belongs to abstract class A and the method call to function 1() is called, the call invokes the function1() of class B. Shouldn't the call invoke function 1() of class C instead? And then function1() of class B will be called after due to the super.function1(). It's not behaving like I thought it would.
    Edited by: crono77 on Jan 10, 2008 8:13 PM

    Nevermind, i found my error :)

  • Parent Child classes

    Hi All,
    I have a really general question that I have not been able to solve.
    Here is my sample code:
    class parent {
    public List mylist
    public parent(){
    child c = new child(this, mylist);
    class child
    private parent p;
    private List mylist;
    private String currentLine ="";
    public child(parent p, List mylist){
    this.p=p;
    this.mylist = mylist;
    BufferedReader in new BufferedReader(new FileReader("test.txt"));
    while ((currentLine = in.readLine()) != null){
    mylist.add(currentLine);
    How do I return mylist in the child class back to the parent class? Or secondly, can I declare a List in the child class and have some way of passing it back to the parent class? I am not very familiar with the parent/child classes. If you can assist, I'd appreciate it. Thanks.

    Actually....the main problem that I have is that I am using multi threading. Right now the problem that I have is that I can't write to the same output file with multiple children threads...not sure why.
    class parent {
    PrintWriter out;
    public parent () {
    out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
    for (int i=0; i<10; i++){
    childthread ct = new childthread(this);
    public synchronized void Output (String output){
    out.write(output);
    }//end class parent
    class child extends Thread{
    parent p;
    public child (parent p) {
    this.p = p;
    public void run(){
    String thisLine = "test";
    p.Output(thisLine);
    }//end class child
    How can I get all of my 10 threads to write to the same file. Since my parent thread is the one with the output file, each time the child thread calls the p.Output and passes the String..it should printout test in my output file...but it does not. Is there any reason why?
    My output file should display "test" ten times. Please let me know what I am doing wrong...or how I can go about writing multiple threads to the same output file. Thank you.

  • How to track child instances in parent class

    I have a **simple** design question about a good way to implement LV OO.
    I have a parent class (multiple instances) with a single child class. The parent class needs to keep track of all "active" instances of the child class because some parent methods must be applied to all children. Is there a way for this to happen automatically in LV? I'm not aware of any, so I assume I will have to use some "register" and "unregister" actions for creation and destruction of child class instances. But how do I track them; where do I store the list?
    It would be easiest to simply add an array of child class references to the private class data of the parent. However, LV seems to not support this due to "circular referencing". I am not familiar enough with OO, nor it's implementation in LV to know what is a good design approach to accomplish this task.
    Any suggestions?

    What I am trying to do:
    I have one or more TCP connections that I am using. The parent class is the TCP connection. The private data for the class is a queue reference. The queue data type is a type def cluster of relevant parameters. The queue has a maximum of 1 element. The reason for this abstraction is that our applications use many TCP connections "simultaneously." As such, we want almost all of the TCP support VIs to be reentrant. This means that we need semaphore action when connection parameters are changed, and we use the queue to achieve this.
    The TCP standard guarantees that each message is delivered intact, but does not guarantee message order. Sending large waveforms (or data from a continuously measuring process) requires additional work to ensure that the messages are correctly reordered on the receive end. We created an Ordered Data Stream (ODS) construct to accomplish this. That is the child class. Each TCP connection has 0 or more ODS. Each ODS inherits all the TCP settings from the parent, and can use the parent communication functions. It seems this is a textbook example of the usefulness of inheritance.
    However, all good parents are able to keep track of their children. The TCP class needs to be able to track all active ODS instances on that TCP connection. We are struggling with the best method to use for the TCP class to keep track of all ODSs. Adding an array of ODS class instances to the TCP "private data" does not work, due to circular referencing between parent and child classes.
    In response to trying a grandparent class:
    We tried using a grandparent class. We added an array of grandparent classes, from which the TCP class inherited. The array is actually ODS instances that have been (2X) upcast from ODS to grandparent (more general class) to be stored in the TCP class data. We found that adding the array of grandparent classes to the TCP class created a VI that could not compile when we attempted to place the type def cluster ("class data") on the block diagram of a VI in the TCP class.

  • Can I make methods which are public in a parent class into private in a child class ?

    I suspect the answer to my question is probably no, but...
    I have a parent class that provides several general purpose methods, I also have a child class which is intended to provide a more specific set of methods for manipulating the data in the class. As a result, calling some of the parent's methods on the child class can provide results that I'd rather not let the users of the child class have to worry about. It seemed (from my rather naive OOP experience) that the nicest way to do this would be to make access to some of the parent's public methods be private in the child class. This doesn't seem to be trivially possible.... ?
    Gavin Burnell
    Condensed Matter Physics Group, University of Leeds, UK
    http://www.stoner.leeds.ac.uk/

    Hi Gavin,
    Unfortuneately I don't think this can be done. You can use an overide VI to change the functionality of a method in a child class but it has to have the same scope and the method it overides.
    Regards
    Jon B
    Applications Engineer
    NI UK & Ireland

  • Parent class private data accessable in Child class?

    Hi!
    I thought that this would be obvious, but my search foo fails me.  Hopefully someone would be kind enough to answer my newbie LVOOP question.
    I have a a parrent class.  This parrent class contains a cluster of class private data.  I setup all the accessor methods to this data.  I create a child class that has functions that need to access data stored in its parrent class.  Its inheritence is set, but when I try to unbundle the class data all I can seem to get to is what is setup in the child class' data cluster.
    I've watched a video and it looked like the data cluster magically appeared and was accessable through the children methods.  What am I missing?
    Thanks for input!
    -nic
    Solved!
    Go to Solution.

    Nickerbocker wrote:
    Well, that makes sense.
    One other quick question.  Is the procedure, New->"VI for Override..." from the context menu of my child class the only way to create a method that overrides the parents method?  Where is the property that defines this newly created VI as overriding my parent's VI?  Can I simply create a VI that is named the same and it have the same effect?
    That is the only method I use but I believe if you get all of your icon patterns and terminal marking as dynamic and all of the other rules, you should be able to do the same thing by hand (I base this guess on the fact I messed with those things and broke my ever-rides).
    The only thing I think has to be done from the project (scripting aside) is to set-up the inheritance.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • A non abstract child class must implement all pure virtual function of  parent abstract class in c++

    Hi,
    In Indesign SDK there is a class  IActionComponent having two pure virtual functions:
    virtual void
    UpdateActionStates(IActiveContext* ac, IActionStateList *listToUpdateGSysPoint mousePoint = kInvalidMousePoint, IPMUnknown* widget = nil) = 0;
    virtual void
    DoAction(IActiveContext* ac, ActionID actionID, GSysPoint mousePoint = kInvalidMousePoint, IPMUnknown* widget = nil)= 0;
    But, the child class
    class WIDGET_DECL CActionComponent : public IActionComponent
    implements only UpdateActionStates function and not DoAction function.
    There is no compilation error and the code is running fine..HOW
    Can some one please explain me?

    Oops!!! there is a small correction in my C++ program. The JunkMethod is being called from the constructor...like the following code.
    #include <iostream.h>
    #include <stdlib.h>
    class Base
        public:
            Base()
                cout<<"In Base Class constructor..."<<endl;
                JunkMethod();
            void JunkMethod()
                TestAbsFunc();
            virtual void TestAbsFunc()= 0;
    class TestAbstract:public Base
        public:
            TestAbstract()
                cout<<"In Extend Class constructor..."<<endl;
            void TestAbsFunc()
                cout<<"In TestAbsFunc...."<<endl;
    int main()
          TestAbstract test;
          return 0;
    }You can see the change in the constructor of the Base class. JunkMethod is being called, just to bluff the compiler to call the virtual method (so that it won't crib saying that abstract method cannot be called from the constructor). When Java is supporting this functionality without giving any errors, C++ gives errors when you call an abstract method from the constructor or fails to execute when I do some work around like this. Isn't it a drawback of abstract funcationality supported by C++ (I'm not sure if it's a drawback or not)
    Regards,
    Kalyan.

Maybe you are looking for