A Reference to itself

Can a class reference itself, for example to give itself as an argument to a class?
I wish to return data multiple times so the normal return statement is not sufficient. Is there a way for a class to pass itself on as a reference?
Mike

Can a class reference itself, for example to give
itself as an argument to a class?
I wish to return data multiple times so the normal
return statement is not sufficient. Is there a way
for a class to pass itself on as a reference?
Are you referring to something like StringBuffer's append?
stringbuf.append('h').append('e').append('l').append('l').append('o');
MikeIf so, something like
public MyClass doSomething()
  //do whatever...
  return this;
}

Similar Messages

  • What is the use of passing object reference to itself ?

    What is the use of passing object reference to itself ?
    regards,
    namanc

    There is an use for returning an object reference from itself, for instance:
    class C {
    public:
         C append(C c) {
             // do something interesting here, and then:
             return this;
    }You can "chain" calls, like this:
    C c = new C();
    C d = new C();
    C e = new C();
    c.append (d).append (e);Maybe the OP has "inverted" the common usage, or thought about a static method of a class C that requires a parameter of type C (effectively being a sort of "non-static method").
    class C {
        static void doAnotherThing (C c) {
            c.doSomething(); //-- effectively C.doAnotherThing(c) is an "alternative syntax" for c.doSomething()

  • Prob with Adaptive Web Service Model and Response with reference of itself

    Hi guys,
    I am facing a problem with the Adaptive WebService Model. I have a WebService which is working properly in a Servlet and also in the web service navigator,
    The webService has a method let´s say create(objectDTO). The structure of objectDTO is like this:
    propertieA
    propertieB
    propertieC
    propertieChildObjectDTO
    So I can pass a list of objectDTOs to the webService. If i import the webService the structure in the model looks fine, but if i want to map it to any context, only the properties A-C are mapped. propertieChildObjectDTO is not mapped.
    Has anyone a clue on how to solve this problem ? I just tried to add and initialize the propertieChildObjectDTO manually but I got a NullPointerException.
    I would appreciate  your help.
    Happy new year guys
    Regards
    Flo

    Guys......
    seems like i can´t reach my requirement with Adaptive Web Service Model:
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/wdjava/faq%252b-%252bmodels%252b-%252badaptive%252bweb%252bservice
    Now I want to make it by hand. How can I import the regarding EJB ?
    Thanks !
    Flo

  • How to get a reference to the owner of a class instance?

    Within a method of a class, how can I get a reference to the
    object containing the class instance?
    To be clear: I have class B that contains a method, say
    "myfunc()". Class A (say, the application itself or a custom
    component) instantiates a new instance of Class B : myclassB=new
    ClassB()
    Now, from within myfunc() can I get a reference to Class A?
    The simplest way here is to pass a "this" reference when
    calling myfunc(), i.e. "myclassB.myfunc(this)" but I would prefer
    not to have to remember to always use 'this'.

    Are these objects within each other. Does classA own classB?
    If that is the case, then Greg is correct and it should be
    available in parentDocument.
    In projects in the past we have created a central
    refObjectLocator object that is available to all objects.
    Mostly we use events to communicate between objects. Dispatch
    an event and let whoever listen for it.
    Here is a copy of our reflocator if you are interested.
    package com.goconfigure.model {
    import mx.collections.ArrayCollection;
    import com.adobe.cairngorm.model.ModelLocator;
    import com.goconfigure.util.HashMap;
    [Bindable]
    public class RefObjectLocator implements ModelLocator {
    // this instance stores a static reference to itself
    private static var refObject : RefObjectLocator;
    public var refObjectHM : HashMap = new HashMap();
    // singleton: constructor only allows one model locator
    public function AppLocator() : void {
    if ( RefObjectLocator.refObject != null )
    throw new Error( "Only one RefObjectLocator instance should
    be instantiated" );
    // singleton: always returns the one existing static
    instance to itself
    public static function getInstance() : RefObjectLocator {
    if ( refObject == null )
    refObject = new RefObjectLocator();
    return refObject;
    public function addRefObject( pRefObject : Object, pName :
    String ) : void {
    refObjectHM.put(pName,pRefObject);
    public function getRefObject( pName : String ) : Object {
    return refObjectHM.getValue(pName);
    public function removeRefObject( pName : String ) : void {
    refObjectHM.remove(pName);
    public function clearRefObject() : void {
    refObjectHM.clear();

  • File Reference Data

    HI!
    Is there a way to access a file reference data?, or do I have
    to upload de file to the server and the download it in order to get
    the file data (This sounds so much as overkilling).
    Also, is there a way to store the file reference data for
    future use, lest say I wish to keep the file reference data so my
    flash applicaction can access the same file in the future, can sore
    this, lest say in a server database or something?
    I hope people form adobe could answer this :)
    Thanks

    Peter,
    Thanks for taking your time to discus about this issue. I've
    always liked the approach flash has had to protect personal data,
    or to be more specific to completely separate Internet form the
    local PC environment. And the proof that you guys are on the right
    track is that there are no FLASH viruses yet.
    Still, and if it's possible I would like to make a few
    suggestions that shouldn't affect the security model but
    definatelly improve the way FLASH communicates with the server:
    1.- Access a File Reference locally, I'm not talking about
    accessing any file on the local PC but the one the user manually
    selected for lets say an upload (Básicaly add an open command
    to fileReference), this would be very usefull since will allow the
    SWF to process the file before sending it, wich for example will
    allow to change an image size before upload or to process a text
    file and upload only the results of this process. I don't see how
    this could be a security risk since you are able to do this with
    the server and a huge everhead today.
    2.- Been able to store the file Reference, again without
    accessing the PATH of the file, but the file reference object
    itself will be most useful to for lots applications, you don't need
    to have access to a directory structure but be able to access a
    file previously selected by the user. Just a while ago I wrote a
    flex application that uploaded a single file to a server every
    hour. I was able to store in a shared object all the paramenters a
    user selected for the upload except for the file reference. This
    meas that the user has to select the file every time it opens the
    application.

  • Do I =Reference a data cell? or =Address the Cell

    OK,
    Anybody know why I cant "=reference" or "=Address" a single cell in Table 1 from Table 3?  I'm using the following Function:  "= ADDRESS (Row 30 :: Column B :: Table 1).  I'm very new and am feeling very, very stupid!!!
    I would also like to be able to add a sheet to the "correct" equation so that I can also reference between sheets, tables, columns and rows.
    Thanks!!!
    A very humbled MAC Fanatic
    Bob
    P.S. the cell I am trying to reference has function "=SUM(B2:B29)".  I have tried using this formula, as well as, a specific number without any equation attached to it... Same results!  TX!!!

    I tink what Yvan was trying to imply was that the reference might not be bad, its the use of the function.
    ADDRESS
    The ADDRESS function constructs a cell address string from separate row, column, and table identifiers.
    ADDRESS(row, column, addr-type, addr-style, table)
    The address function takes multiple arguments, that then return a string that LOOKS like a true reference. This can be used by  Indirect to return a true reference that can be utilized inside other functions. It allows a refrence to be constructed from the results of other cells values.
    I utilize this one often if I have a single table for each month and need to create a  summary table that reports on each other table. I just list the tables as a column of data, refer to it from an address inside indirect within my sum or average, or offset, and fill down. It gives the ability of adding more tables, users etc... and never having to rewrite the formulas. Just fill down.
    The other thing that is wrong is the format of the reference posted itself though:
    Row 30 :: Column B :: Table 1
    would actually be:
    Table 1::B30
    So, when you put it all together, the user is trying to put a SUM result as the Row argument of a address function without providing at least the minimum required arguments for Address. While possibly parsing the reference wrong.
    Jason

  • Searching for Staic VI References

    I recently found out about a neat way to open vi references in labview by using the static vi reference.  Today I tried to open an app in 8.5 and couldn't because of a whole bunch of bugs and problems with labview 8.5.  Then when I looked at the 8.5 known issues page I saw:
    4CKERKC3
    Building an application that contains a VI that has a static VI reference to itself throws Error 7
    Building an application that contains a VI that has a static VI reference to itself fails throwing the following errors: "LabVIEW cannot find a file that is a dependency of a Startup, Exported, or Always Included VI. File Not Found: The missing file might be referenced by one of the libraries included in the build or by the file - test.vi." or "Error 7 LabVIEW: File not found. The file might have been moved or deleted, or the file path might be incorrectly formatted for the operating system. For example, use \ as path separators on Windows, : on Mac OS, and / on Linux. Verify that the path is correct using the command prompt or file explorer."
    Workaround—Don't use static VI referece, instead use the Open VI ref prim, passing it the the Current VI path constant.
    Date Added—09/27/2007
    Return to top
    Now I am very worried.  If this didn't work right in labview 8.5, does it work right in labview 8.2?  Is there a way to search for static references in a project?  I realize now that it is a new feature and I should have never used it.  But now I can't rememeber all teh places I used it.  Any suggestions?
    -Devin
    I got 99 problems but 8.6 ain't one.

    That sounds like one of my bugs and I probably found it in LV 8.2.
    If you open all of the top level VI's, then serach all of the VI's in memory, it should show up.
    Ben
    Message Edited by Ben on 10-18-2007 12:00 PM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Static_ref.PNG ‏48 KB

  • Using static VI references in an application

    Hello all you helpful forum-goers!
    I am using 4 different static VI references hooked directly to "Run VI" invoke nodes, with the "Wait Until Done" and "Auto Dispose Ref" parameters both False, to run four VIs dynamically, each of which does nothing except call my re-entrant serial port input/output VI with a different COM port index number.  Overall this is working pretty well.  However, I have a couple questions about improving my setup.
    1) Is it possible to somehow set an input parameter to the re-entrant serial port VI, and thereby be able to Invoke it directly four times in a for loop, each with a different input value?  I'm not sure how I would do that, except that I've heard that you can set the value of a control of a VI using a reference to it.  I also worry that using the same static VI reference to Invoke the VI 4 times would somehow re-start the same dynamic VI instance 4 times, instead of spawning 4 copies of it.  However, this solution would allow me to delete the 4 VIs which do nothing except call the re-entrant VI, and my code would be simpler and more expandable (e.g. making it easy to interact with 8 serial ports in the future just by increasing the number of for loop iterations).
    2) It seems to be required for me to add the 4 VIs which I Invoke dynamically to my lvproj file, and then add to the "Always Included" section of my application build properties in order for them to be included in my application executable.  This was what I had to do in previous versions of my code when I referenced the VIs via a path name, but now that I changed to using static VI references, I thought they would be included automatically.  LabVIEW already knows to automatically load them in memory (e.g. when I do a search it searches them even when they are not open), and they are included in the Dependencies list in my LabVIEW project, so why would they not be built in to my executable?  I'd prefer not to have to add them explicitly, as it is just one more thing to forget if I change it in the future.  Is there a setting or something somewhere which I can change so that they will be included in the executable automatically?
    Thank you very much for your time and assistance, as always!
    -Joe
    Solved!
    Go to Solution.

    Nope.  If you look at the Help for the "Run VI" method, you find the following information for "Auto Dispose Ref":
    "If TRUE, the target VI detaches the reference from the main VI.  When the target VI finishes executing, LabVIEW automatically disposes of the reference, along with the parallel data space.  If FALSE, the main VI retains control of the target VI."
    So by setting "Auto dispose" to T, you pass control of the reference to the subVI itself, and LabVIEW will dispose of the reference when the subVI finishes running.
    I will second Jeff and urge you to get rid of the global variable!  I haven't used a global variable in something like 14 years.  I haven't needed to.  Myself, I love a good notifier and would urge you to use a notifier instead of a queue if you're going to be spawning VIs.  Why?  Because the first instance of your spawned VI to receive the "stop" message from the queue will remove that message from the queue, thus preventing the other instances from receiving the message.  So you'll have to send the message repeatedly and hope that everyone eventually receives it.  If you use a notifier, anything that contains a "Wait on Notification" with that notifier reference will receive the message.  I think you want multiple listeners here, right?
    Ok, this afternoon I'll try to write some dummy code with a statically called VI in it, compile it into an exe, and see if I can duplicate your problem...
    One question, were you just using the static VI reference by itself to call your VI, or were you using it the same way I showed in my earlier post, with "Open VI reference"?  I'm just trying to look for differences between what I've done in the past which has worked, and what you're doing now which isn't working...
    Jeff, what say you?

  • Scheduling Agreement reference.

    Hi,
    We used to copy the previous FY Scheduling agreements and create new SAs every year.
    Due to a requirement, we were trying to find out the original SA ref in the new, copied SA. But, unable to get the same. (It is unlike a PO which has the ref. of PO from where it is copied).
    Please revert if the ref. can be tracked from the ME33L screen. Even otherwise, please let me know from where I can get this info. (like tables).
    Regards,
    Siva

    Hi
    In ME31L/ME32L/ME33L at header level you can maintain the reference data like purchase order.
    But you should have maintained when you copy SA. I dont think the system will copy and store the reference by itself.
    Hope it helps
    Karthik
    Edited by: Karthik on Jun 27, 2011 10:06 AM

  • Subroutine execution priority with Call By Reference nodes

    Hi -
    I have a VI which contains a Call By Reference node. I would like this VI to run with subroutine execution priority (the VI is small, is called frequently, and must run quickly). The VI being called by reference is itself set to run with subroutine execution priority. However, I get an error which reads: subroutine priority VI cannot contain an asynchronous node. What is asynchronous about a call-by-reference to another subroutine VI? Is there any way to get around this? Thanks.
    Jason
    Jason Rolfe

    This is what the help files mention:
    Subroutine priority VI cannot contain an asynchronous node
    This VI has subroutine priority selected in the Execution page of the VI Properties dialog box. It cannot use an asynchronous node on its block diagram. Asynchronous nodes, such as dialog boxes, are supposed to allow other VIs on the same thread to continue to execute while they wait to complete their own execution. However, subroutine priority VIs block the execution of other VIs on the same thread until the subroutine priority VIs finish execution.
    You can correct this error in the following ways:
    Change the execution priority of this VI. To change the priority, right-click the VI icon in the upper-right corner of the front panel or block diagram window, and select VI Properties from the shortcut menu to display the VI Properties dialog box. Select Execution from the top pull-down menu of the VI Properties dialog box, and change the priority in the Priority pull-down menu.
    Remove the asynchronous node.
    I am affraid that the call by reference node is asynchronous.
    aartjan

  • VI Server and "this" reference

    Hallo LabVIEWers,
    not a real problem (at the moment so far, but who knows ?). Is there a
    G-construct similar to the "this" reference in Java or C++, so that a VI can
    act on its own methods or property via the VI-Server. For example open
    reference to itself, modify some properties, call some methods, and close
    reference ?
    Best regards
    Oli

    Sure, place a property node or invoke mode on the block diagram and right
    click it. Select "Select VI Server Class >" and click on "VI". you can
    then select properties and methods for that VI. By not wiring a reference
    in, the node refers to the vi it resides in.
    Jared
    "Oliver Friedrich" wrote:
    >Hallo LabVIEWers,>>not a real problem (at the moment so far, but who knows
    ?). Is there a>G-construct similar to the "this" reference in Java or C++,
    so that a VI can>act on its own methods or property via the VI-Server. For
    example open>reference to itself, modify some properties, call some methods,
    and close>reference ?>>Best regards>>Oli>>

  • Comparison of references failed

    Hello,
    recently I've observed a strange behavior when trying to compare two references referring to the same typedefed controls.
    What I want achieve:
    I've created a typedefed control (a cluster of radio buttons with additional informations) for use on the UI front end. To manipulate the contents I've created a subVI which takes a reference of the front end control. The functionality is not of interest - it controls the values represented by the radio buttons, so the whole thing is some kind of "advanced radio button control".
    Now I need to address the data structure of the cluster components. The first approach was to compare the labels with a hard-coded string. But then I discarded this first attempt because if somebody changes the labels of the front end control the subVI won't work anymore without a visible reason. So I decided to compare references.
    So far the introducing story...
    Now I observed some kind of pathologic behavior - and that's my question:
    Attached to this post is a small demonstration VI which should make clear what is the issue about.
    First I've created an instance of the control. For simplicity let's call it "MyControl".
    Then I created two references to this object.
    The first one by selecting the "VI Server Reference" from the "Application Control" menu. Done that, a right click on the reference and choosing the menu item "Link to .../Pane/MyControl" creates the link to the control. If I open the same menu entry then there are no check-marks in the menu (this becomes important later).
    The second I've created by a right click onto MyControl and selecting the menu item "Create/Reference". As difference to the first this reference shows checkmarks in the "Link to ..." entry of the right-click-menu.
    Both references seem to be linked properly to the control if used to read or write any properties. But if I try to compare them using the "Equal?" or "Not Equal?" functions of the "Comparison" palette the result is inequality. Unless the type-casted numbers or the references by itself are compared.
    I know the value of the references may differ in value, but the comparison functions should handle that by resolving the references before the equality check. (see the documentation of the comparison palette)
    Why are the references unequal? Also a right click onto the control or it's terminal and selecting "Find all references" from the right-click-menu finds only the first of both references.
    Is it an issue of referencing the typedef and the structure the typedef contains? (only typedefed controls behave like described, after disconnection from typedef the comparison works)
    One more thing I found out: selecting "Link to .../Pane/MyControl" from the right-click-menu of the second reference (the check-marked entry) links the reference properly, even for the comparison functions and the "Find all references" function. Done this, the check-marks vanish.
    How can I ensure proper linked references? Is there a better - more stable - way to refer to a control than by label or a reference?
    Is it a bug? I'm using LabView 2011 (without SP1) on a win7 notebook.
    Solved!
    Go to Solution.
    Attachments:
    Reference Comparison failed.zip ‏17 KB

    P@Anand wrote:
    Sorry I don't understand. Do you mean a control can have 2 different reference numbers? (I don't think so)
    Just look at the Type Cast to U32.  That is the actual reference number.  For me, 2011 SP1 had different numbers; 2013 SP1 had the same number.  So it looks like NI fixed it either with 2013 SP1 or with a patch since.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Reference Comparison failed_2011SP1.png ‏25 KB
    Reference Comparison failed_FP2013SP1.png ‏25 KB

  • Null And " "

    What is the difference between these two lines of codes?
    String currentFile = null;
    String currentFile = "";
    Edited by: AMARSHI on Jul 10, 2008 7:07 AM

    The reference variable itself, takes up the same amount of space, of course, as all references are the same size. Now, the object on the heap is a different story. With null there isn't one, of course (or if there is there is only one for the entire VM), and for the second a String object will be created in the String pool (once again, only one for the entire VM that every = "" assignment will use). But really, what difference does it make? If there is a difference, it is on the order of a few bytes (at max) for the entire VM, and if this is a concern, your probably doing something else greviously wrong. This miniscule difference should not concern you.
    Edit: And "nulling" variables to "save" memory is also not something you should be concerned with. Either the variable will go out of scope and the object garbage collected anyway, or it's in constant use and so will not be taking up any extraneous heap space. If one of those is not the case, you are, once again, doing something greviously wrong.

  • Open second vi and close the first vi

    i want to open the second.vi to be open from one.vi and,, and at the same time i want to close one.vi,,,
    i find may answers in labview about this but any of them could not setisfy my requirment,,,
    manisha

    What is your requirement?
    The way to do this is with the VI Server. From one.vi get a reference to second.vi and launch it using the Run method. Then have one.vi close itself by getting a reference to itself and closing its front panel. Note that your code should also be written such that one.vi stops executing once that occurs otherwise it will keep running even though the front panel is closed. So, if you have some sort of while loop that continuously runs you will need to stop it.

  • Running Independen​t VI's

    I've tired to have one vi open a second vi and then close the first vi leaving the second vi running. I can't seem to get this to work using the second vi opening a vi reference too itself as I was led to believe. Can anyone provide help or an example?

    The examples submitted by other contributors work because the front panel of the second VI is opened. This condition is sufficient to keep second VI in memory when first VI stops and closes.
    However, if the second VI would not have its panel opened, it would be aborted when first VI stops because LabVIEW releases a VI from memory when its panel is closed and no running VI has reference opened to it. That is why you have been told that second VI must open a reference to itself in order to stay in memory when first VI stops.
    The problem you probably have is a race condition: first VI opens a reference to run second VI but it exits too soon, before second VI has time to open a reference to itself. The solution is that first VI waits
    some time to make sure that second VI opens it self-reference.
    Instead of waiting a fix time which could sometime be not enough, I do the following: second VI opens a reference to itself and writes it on a front panel refnum indicator named "Self Ref". First VI, after running second VI, polls "Self Ref" value (using "Get Control Value" on second VI) and test it until it returns a valid refnum ("Not a Path/Refnum" node).
    That being said I have read that in LabVIEW 6.1 there is an option on "Open VI Reference" node to open another VI, detach it from first VI and automatically close the refnum when second VI stops. I have not 6.1 yet to test it but it seems to neatly address and solve this issue.
    LabVIEW, C'est LabVIEW

Maybe you are looking for