Passing Array variables between objects

While troubleshooting a Flash app, it took me hours to figure
out that you need to make a duplicate of an Array variable if you
are passing it between objects. Otherwise, any alterations that you
make to the array will result in the original array being altered
as well as the "new" array.
I'm no developer, can someone please explain why you have to
do this? Or, give me an instance when you wouldn't want to make a
duplicate? Just trying to understand.
Thanks.

it is because if you do something like this
a=[1,2,3]
b=a
all you are doing is storing a reference to a in a variable
b.Instead, either copy oput the array again or use one of the array
methods which return an array eg
b=a.slice()
b=a.concat()

Similar Messages

  • Passing Array of java objects to and from oracle database-Complete Example

    Hi all ,
    I am posting a working example of Passing Array of java objects to and from oracle database . I have struggled a lot to get it working and since finally its working , postinmg it here so that it coudl be helpful to the rest of the folks.
    First thinsg first
    i) Create a Java Value Object which you want to pass .
    create or replace and compile java source named Person as
    import java.sql.*;
    import java.io.*;
    public class Person implements SQLData
    private String sql_type = "PERSON_T";
    public int person_id;
    public String person_name;
    public Person () {}
    public String getSQLTypeName() throws SQLException { return sql_type; }
    public void readSQL(SQLInput stream, String typeName) throws SQLException
    sql_type = typeName;
    person_id = stream.readInt();
    person_name = stream.readString();
    public void writeSQL(SQLOutput stream) throws SQLException
    stream.writeInt (person_id);
    stream.writeString (person_name);
    ii) Once you created a Java class compile this class in sql plus. Just Copy paste and run it in SQL .
    you should see a message called "Java created."
    iii) Now create your object Types
    CREATE TYPE person_t AS OBJECT
    EXTERNAL NAME 'Person' LANGUAGE JAVA
    USING SQLData (
    person_id NUMBER(9) EXTERNAL NAME 'person_id',
    person_name VARCHAR2(30) EXTERNAL NAME 'person_name'
    iv) Now create a table of Objects
    CREATE TYPE person_tab IS TABLE OF person_t;
    v) Now create your procedure . Ensure that you create dummy table called "person_test" for loggiing values.
    create or replace
    procedure give_me_an_array( p_array in person_tab,p_arrayout out person_tab)
    as
    l_person_id Number;
    l_person_name Varchar2(200);
    l_person person_t;
    l_p_arrayout person_tab;
    errm Varchar2(2000);
    begin
         l_p_arrayout := person_tab();
    for i in 1 .. p_array.count
    loop
         l_p_arrayout.extend;
         insert into person_test values(p_array(i).person_id, 'in Record '||p_array(i).person_name);
         l_person_id := p_array(i).person_id;
         l_person_name := p_array(i).person_name;
         l_person := person_t(null,null);
         l_person.person_id := l_person_id + 5;
         l_person.person_name := 'Out Record ' ||l_person_name ;
         l_p_arrayout(i) := l_person;
    end loop;
    p_arrayout := l_p_arrayout;
         l_person_id := p_arrayout.count;
    for i in 1 .. p_arrayout.count
    loop
    insert into person_test values(l_person_id, p_arrayout(i).person_name);
    end loop;
    commit;
    EXCEPTION WHEN OTHERS THEN
         errm := SQLERRM;
         insert into person_test values(-1, errm);
         commit;
    end;
    vi) Now finally create your java class which will invoke the pl/sql procedure and get the updated value array and then display it on your screen>Alternatively you can also check the "person_test" tbale
    import java.util.Date;
    import java.io.*;
    import java.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.driver.*;
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    public class ArrayDemo
    public static void passArray() throws SQLException
    Connection conn = getConnection();
    ArrayDemo a = new ArrayDemo();
    Person pn1 = new Person();
    pn1.person_id = 1;
    pn1.person_name = "SunilKumar";
    Person pn2 = new Person();
    pn2.person_id = 2;
    pn2.person_name = "Superb";
    Person pn3 = new Person();
    pn3.person_id = 31;
    pn3.person_name = "Outstanding";
    Person[] P_arr = {pn1, pn2, pn3};
    Person[] P_arr_out = new Person[3];
    ArrayDescriptor descriptor =
    ArrayDescriptor.createDescriptor( "PERSON_TAB", conn );
    ARRAY array_to_pass =
    new ARRAY( descriptor, conn, P_arr);
    OracleCallableStatement ps =
    (OracleCallableStatement )conn.prepareCall
    ( "begin give_me_an_array(?,?); end;" );
    ps.setARRAY( 1, array_to_pass );
         ps.registerOutParameter( 2, OracleTypes.ARRAY,"PERSON_TAB" );
         ps.execute();
         oracle.sql.ARRAY returnArray = (oracle.sql.ARRAY)ps.getArray(2);
    Object[] personDetails = (Object[]) returnArray.getArray();
    Person person_record = new Person();
    for (int i = 0; i < personDetails.length; i++) {
              person_record = (Person)personDetails;
              System.out.println( "row " + i + " = '" + person_record.person_name +"'" );
                        public static void main (String args[]){
         try
                             ArrayDemo tfc = new ArrayDemo();
                             tfc.passArray();
         catch(Exception e) {
                        e.printStackTrace();
              public static Connection getConnection() {
         try
                             Class.forName ("oracle.jdbc.OracleDriver");
                             return DriverManager.getConnection("jdbc:oracle:thin:@<<HostNanem>>:1523:VIS",
                             "username", "password");
         catch(Exception SQLe) {
                        System.out.println("IN EXCEPTION BLOCK ");
                        return null;
    and thats it. you are done.
    Hope it atleast helps people to get started. Comments are appreciated. I can be reached at ([email protected]) or [email protected]
    Thanks
    Sunil.s

    Hi Sunil,
    I've a similar situation where I'm trying to insert Java objects in db using bulk insert. My issue is with performance for which I've created a new thread.
    http://forum.java.sun.com/thread.jspa?threadID=5270260&tstart=30
    I ran into your code and looked into it. You've used the Person object array and directly passing it to the oracle.sql.ARRAY constructor. Just curios if this works, cos my understanding is that you need to create a oracle.sql.STRUCT out of ur java object collection and pass it to the ARRAY constructor. I tried ur way but got this runtime exception.
    java.sql.SQLException: Fail to convert to internal representation: JavaBulkInsertNew$Option@10bbf9e
                        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
                        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
                        at oracle.jdbc.oracore.OracleTypeADT.toDatum(OracleTypeADT.java:239)
                        at oracle.jdbc.oracore.OracleTypeADT.toDatumArray(OracleTypeADT.java:274)
                        at oracle.jdbc.oracore.OracleTypeUPT.toDatumArray(OracleTypeUPT.java:115)
                        at oracle.sql.ArrayDescriptor.toOracleArray(ArrayDescriptor.java:1314)
                        at oracle.sql.ARRAY.<init>(ARRAY.java:152)
                        at JavaBulkInsertNew.main(JavaBulkInsertNew.java:76)
    Here's a code snippet I used :
    Object optionVal[] =   {optionArr[0]};   // optionArr[0] is an Option object which has three properties
    oracle.sql.ArrayDescriptor empArrayDescriptor = oracle.sql.ArrayDescriptor.createDescriptor("TT_EMP_TEST",conn);
    ARRAY empArray = new ARRAY(empArrayDescriptor,conn,optionVal);If you visit my thread, u'll see that I'm using STRUCT and then pass it to the ARRAY constructor, which works well, except for the performance issue.
    I'll appreciate if you can provide some information.
    Regards,
    Shamik

  • How to pass Array of Java objects to Callable statement

    Hi ,
    I need to know how can I pass an array of objects to PL/SQL stored procedure using callable statement.
    So I am having and array list of some object say xyz which has two attributes string and double type.
    Now I need to pass this to a PL/SQL Procedure as IN parameter.
    Now I have gone through some documentation for the same and found that we can use ArrayDescriptor tp create array (java.sql.ARRAY).
    And we will use a record type from SQL to map this to our array of java objects.
    So my question is how this mapping of java object's two attribute will be done to the TYPE in SQL? can we also pass this array as a package Table?
    Please help
    Thanks

    I seem to remember that that is in one of Oracle's online sample programs.
    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html

  • Please help!! Can I pass a variable between 2 swf's that are on different html pages?

    Hey,
    Does anyone know how to pass a variable (string) from one swf
    to another if there in separate html pages?
    I assume I’d have to send the variable from the first
    page and load it into the second but I don’t know what
    functions or code I should be using. Any suggestions would be a
    HUGE help.
    Thanks
    If it helps: I’m creating a log in and sign up sheet
    that can be accessed from several sites. I’d like to record
    which site the user has come from when they signup.
    Thanks

    if they are open at the same time (for the same user), you
    can use the localconnection class to communicate between the
    two.

  • How can I pass a variable between JSP and Role Form

    I need to pass a variable from (a copy of) applicationmodify.jsp to the IDM Role Form so that the variable is available within the Role Form at display. We've tried getAttribute and setAttribute modifying both the Role Form and the applicationmodify JSP and can get the form to the role form but not accessible but have had no other success. Has anyone had any success in doing this? Any suggestions would be appreciated.

    if by _root level you mean you're loading something into
    _level0 you can't won't be able to use the localconnection. the
    sharedobject is your only option.

  • Passing a variable between applications

    Hi,
    I would like to pass a variable from a jsp page in a portal application into KM repository filter with user session context. For example, I will set { var1="sample data" } in the portal application and read it in the repository filter. Actually I am looking for a model like import/export statement in ABAP.
    Thank you,
    Orkun

    Hi Orkun
    Considering you aren't trying to send the variable in your url, you must concatenate your variable inside your well formed url and it must be considered during the iView configuration in your portal.
    KM is able to get all posts from the client once you have informed first the name of variable that  you are posting in your form.
    There's no need to use session context at this point, we must consider session contexts when talking about statefull session beans.

  • Passing array to remote object.

    Hi All,
       I'm able to pass 'String' to RemoteObject method but can someone please let me know how to pass array to remoteobject.
      Say I have following array:
       public var mySourceDataProvider:Array = new Array({isRowSelected: false, name:'Name1', age:10, comment:'Comment1'},
                             {isRowSelected: false, name:'Name2', age:20, comment:'Comment2'},
                             {isRowSelected: false, name:'Name3', age:30, comment:'Comment3'},
                             {isRowSelected: false, name:'Name4', age:40, comment:'Comment4'});
      I'd like to pass this array to RemoteObject method.
      Thanks in advance.
    Regards,
    Sharath.

    Say I have 'mySourceDataProvider' array, which I'd like to pass to RemoteObject method in backend....how to declare this RemoteObject method which takes array from flex UI.
    If this not clear then let me know, I'll try to send some sample code...

  • Passing a variable between functions [Silly Question]

    Hey, I am trying to write a program (who wouldve guessed) and I have the following problem. I set a variable in one function, but when I access it from another one, it is "undefined". How can I pass the variable, so both the functions see it? I thought the "public" class when defining a function should take care of that, but I was obviously wrong. Please help? (Code following...)
    public function dalsi_slovicko():void {
                   var pocet_slovicek = slovnikXML.slovicka.elements("*").length();
                   var cislo_slovicka = randomNumber(0, pocet_slovicek);
                   var slovicko_1 = ask(cislo_slovicka, "en");
                   var slovicko_2 = ask(cislo_slovicka, "cs");
                   slovicko1.text = slovicko_1;
    private function kontrola() : void {
              if (nazor.text == slovicko_2) {
                    dalsi_slovicko()
              else {
                   Alert.show("Špatně!! \n Slovicko_2 bylo:" + slovicko_2);
    Thanks...

    create the variable outside the functions so it is accessible for all the functions.
    private var slovicko_2;
    public function dalsi_slovicko():void {
                var pocet_slovicek = slovnikXML.slovicka.elements("*").length();
                 var cislo_slovicka = randomNumber(0, pocet_slovicek);
                 var slovicko_1 = ask(cislo_slovicka, "en");
                 slovicko_2 = ask(cislo_slovicka, "cs");
                 slovicko1.text = slovicko_1;
    private function kontrola() : void {
              if (nazor.text == slovicko_2) {
                   dalsi_slovicko()
              else {
                  Alert.show("Špatně!! \n Slovicko_2 bylo:" + slovicko_2);
    Also when you declare variables, set  appropriate datatypes

  • Passing array to ActiveX object method

    I need to pass the array by pointer as a parameter into method of an ActiveX object. More detailed - to ActiveX/COM object which represents the arbitrary waveform generator hardware.
    How it is possible to do in LabView?
    Thank you!

    There is declaration of COM method I need to use:
    [id(15), helpstring("method SetData")]
    HRESULT SetData([in] DOUBLE* newVal, [in] ULONG length, [in] USHORT MBIndex, VARIANT_BOOL bUpdate).
    The main important psrsmeters is newVal and length.
    Unfortunately I can not wire an array to NewVal.
    There is a screenshot from LabView in the attachement...
    Attachments:
    array_to_COM.jpg ‏17 KB

  • Help: I am trying to pass a variable between classes

    I am trying to pass data in a variable inbetween two classes is there any suggestions as to how to do this? Here is a example of the code I am trying to pass MqMessage to the class MqLog.
    if(MqMessage.equals("END"))               
                                       finalize();
                                       System.exit( 0 );
                             else //else build flat file and launch docusolve
                                       MqLog tempMqLog = new MqLog();
                                       tempMqLog.levelThreeDiagnostic();
                                       aRuntime = null;
                                       aProcess = null;                                   
                                  }

    I don't really undestand what you are asking specifically. If you only want to transfer a value from one Object to another Object, then you should just use a set method:
    if (objectOne.getValue().equals("END"))
    end();
    else
    objectTwo.setValue(objectOne.getValue())

  • Java passing array variables - number work - letters are undefined

    Hello Forum,
    This is my first post so be kind.
    The problem is with passing variables? to functions (a,b,c)
    I have it working fine if the value is a number without any spaces
    however if you add a letter at all, i then get an error that says the exact variable is undefined.
    12345 works perfect no errors, everything passes through as it should, 100% perfect
    1234512345 same as above
    a12345 produces an error ie "a12345" is undefined code 0
    12345a produces an error expected ')'
    12345 12345 produces an error expected ')'
    anything other than an integer causes an error.
    I have no clue why there are 2 different errors for what seems to be 1 problem?
    do i need quotes around the variables? ("a","b","c") ?
    I don't have a guess at this, as it works fine with the numeric value only, the values are all arrays being passed through functions through flash to more functions, etc...
    really slamming my face into a pile of broken glass on this one.
    help would be great.

    I want to thank you both for your prompt response. My java was actually coded correctly, it was the call to java from flash
    flash as2
    WRONG - getURL('JavaScript:moveback();clicker(' + root.sms + ', ' + root.fadd + ');', "_self");
    RIGHT - getURL('JavaScript:moveback();clicker("' + _root.sms +'", "' + _root.fadd + '");', "_self");
    This one is solved! Delete this thread Mods!
    Thank you so much, this forum rocks!

  • How to pass local variables between different sequence files?

    Actually i want to pass the data (local variable) from my process model file to a client file. The client file only has the callbacks and those callbacks require some parameters as input which is available in local variables of my process model sequence file. I do not want to use Station Globals.
    Please tell me any other way by which i can pass that data.

    Which Locals do you want from the model.  Every sequence has it's own Locals and there are a bunch of sequences in every process model.  Do you want the entry point's Locals?  A callback's Locals?  Just one of the sequence's Locals?  Some Models have way more entry points than others.  What if your sequence file is ran with a different entry point?
    One option is to create your own callback in the model and pass the data to it as parameters.  Then add that callback to your client sequence file and get it out of the parameters.
    If you simply want the entry point's locals and you are in your Main Sequence then you could use RunState.Caller.Locals.VariableName.  This assumes you will use the same entry point every time you run that sequence file.  Or assumes that every entry point you run has the same Local variable name.
    Maybe there is an API method that exposes what you are looking for.  What is your goal?
    Regards,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • Passing array variables into functions (and why I'm hopeless at arrays)

    OK, I have spent a day on this now and have done some fairly
    extensive searching online. The problem is - I am hopeless with
    arrays (and probably just actionscript generally for that matter)
    I want to create an array of buttons, so I set up an array of
    actions, step through each item and then try to pass that array
    action into an onclick button for an attached button
    The problem I have is that the onclick function ALWAYS
    returns the last item in the array.
    Help!
    Code below:
    ----------------------------------------------------------------

    the reason for this, is that once the for loop executes, the
    'last' value is the only one remaining. what one needs to do here
    is 'store' the string in a newly created property on each button,
    like this:

  • Re: Passing a Variable Between 2 Classes (school project)

    return job.customerCode(custCd);There is no customerCode() method, there is also no custCd variable.

    public double getApplicableDiscount()
        return applicableDiscount;
    }There is no applicableDiscount variable.

  • Passing string variables between servlets

    Hello
    I need to pass an SQL string constructed in Java servlet A to Java servlet B where it can be executed.
    For example:
    In servlet A I have:
    String cmd = ("select x from y where z");
    cmd is then passed to the server as a hidden form field and read by servlet B as:
    if (paramName.equals("cmd")) {
    String cmd = paramValue;
    However, displaying cmd in servlet B shows only:
    "select"
    Is there a way around this at all? That is, other than converting all spaces to another character in servlet A and reinstating the spaces in serlvet B?
    Thanks
    Martin O'Shea.

    marti,
    you are posting the form aren't you... not getting it?
    I'm suspecting that it's a side-effect of URL rewriting.
    http://en.wikipedia.org/wiki/Rewrite_engine
    And of course a better approach is create user model in the session facade... and if you don't know what that means then forget it.
    keith.

Maybe you are looking for

  • Error in VF02 while releasing Billing Document to Accounting

    Hi, I am  getting the below error while releasing the billing document to Accounting.Kindly help me in solving the below error.it would be a great help to me. Error Message is- System error in routine FI_TAX_GET_TAXJCD_LEVELS error code 2 function bu

  • Records Management issue

    Hello, I'm trying to create a Records Management demo scenario, but i got a error trying to create a Record from a model previously created: "No record model registered. Maintain in the registry." Can anyone give me a tip for solve this issue? Regard

  • Re: Saudi Direct Deposit issue

    Hi, I am facing a similar problem like others did in a previous forum thread: Saudi Direct Deposit issue After i run the PrePayments process i could see in SOE the correct values for Payment Method with all bank details and payment amount. But when i

  • Change of language in Payment terms

    Dear Experts, I have created payment terms and tried to add german language, i could not find the language in OBB8. Could anybody please suggest why this is happening? Thanks, Meena

  • Is there a "slim" effect Motion(5)

    I've seen some (older) movies and especially credits filmed with a narrowing effect and wondered if it was possible with motion. And while I'm at it, what about a saturated/technicolor(?) effect? Sorry, complete novice that hasn't yet purchased Motio