Bugger, thats what I suspected, but it was worth asking :-)


Matt Benic
Axapta Developer
UTi Sun Couriers Division
  -----Original Message-----
  From: Jacob Hjelmer Nielsen [mailto:[EMAIL PROTECTED]
  Sent: 04 June 2004 02:06 PM
  To: [EMAIL PROTECTED]
  Subject: RE: [development-axapta] Passing containers by reference


  The only way to do this is to wrap it into a class.!

  :-J

  System developer
  Jacob Hjelmer

  Thy Data Center Development A/S
  S�vej 13b
  DK-3460 Birker�d
  Denmark

  Phone : +45 96 170 470
  Fax   : +45 45 824 544

  URL   : http://development.thydatacenter.dk/
<blocked::http://development.thydatacenter.dk/>

    _____

  From: Matt Benic [mailto:[EMAIL PROTECTED]
  Sent: 4. juni 2004 10:52
  To: Axapta Dev
  Subject: [development-axapta] Passing containers by reference

  Hi,
  I am currently trying to convert a class-based profiling utility to be
able
  to make use of global functions. What I want to do is allow the user of
the
  functions to pass in a (potentially empty) container, and work with that.
  So, for example, if a function is passes a parameter container timer I
want
  to be able to pass it onto my (Global) start function and NOT have to
return
  a new container, so that the actual container passed in is altered. Is
this
  possible? At the moment I have the following method in Global:
  public static void SUN_StartTimer(container timer)
  {
      boolean isTiming;
      int timeStarted;
      int timeElapsed;
      int numStarts;
      ;
      [isTiming, timeStarted, timeElapsed, numStarts] = timer;
      isTiming = true;
      timeStarted = WinAPI::getTickCount();
      numStarts++;

      timer = conpoke(timer, 1, isTiming, timeStarted, timeElapsed,
  numStarts);
  }

  Which I call in a job as follows:
      container con;
      ;
      SUN_StartTimer(con);

      print con;


  Con always ends up being an empty container. I found the topic below in
the
  Dev guide, which says that all parameters are passed by value, but I am
  kind-of hoping agains hope that there is a way to forcibly pass by
  reference, or to specify a parameter as an out parameter. The reason I
dont
  want to have to actually return the container is that it removes the
  possibility of returning something else.

  Thanks,


  Matt Benic
  Axapta Developer
  UTi Sun Couriers Division

  >From Dev Guide, Axapta Language Reference -> Methods and Variables ->
  Parameters and scoping:

  Parameters and scoping
  The scope rules in X++ state that all methods have their own scope. To use
  data from one scope in a different scope, you have to transfer the data
into
  the other scope, using parameters.

  A method can take one or more arguments. Within the scope of the method
  these parameters are treated like local variables, initialized with the
  value from the parameter in the method-call. Here is an example:



        Class declaration
       Method methodQ

        class Parameter
       void methodQ(int aval, real bval)

        {
       {

        int a;
       a = aval;

        real b;
       b = bval;

        }
       }


  Here, a class called Parameter is declared. The class has a method
  (methodQ), which takes two parameters, an integer and a real. Four
variables
  are visible within the scope of methodQ: aval, bval, a and b The a and b
  variables are in the scope as they are defined class declaration for the
  class.

  Assume that ParameterObject is an instance of the Parameter class. If
  methodQ is invoked on ParameterObject, like this:

  ParameterObject.methodQ(1,2.0);

  Then aval is set to the value 1 within the method and the variable bval is
  set to 2.0 (it is a real) within the method. The two variables a and b in
  the ParameterObject are set to 1 and 2.0, respectively. You can pass the
  value of any _expression_ as parameters.

  Note that all parameters are passed by value. This means that you can not
  change the value of the original variable, but only the local variable in
  the method, which is a copy of the original. Here is an example:



        Class declaration
       Method MethodA
       Method MethodB

        class ByValue
       void MethodA(int i)
       void methodB()

        {
       {
       {

        }
       i = i + 1;
       int i = 3;


       print i;
       print i;


       }
       this.MethodA(i);



       print i;



       }


  Here, a class ByValue is declared with two methods, MethodA and MethodB.

  MethodB has a local variable named i, which is used as a parameter to a
call
  methodA.

  MethodA uses a parameter called i and therefore has a local variable
called
  i. This local variable has the value of the variable i in methodB (as it
is
  used as parameter in the call).

  The result of invoking MethodB is a print of the value of i in MethodB
  before and after MethodA is invoked, and a print of the value of i inside
  methodA, which then is the parameter i.

  The result of these three prints: 3 4 3

  illustrates that the two i variables are two different variables and hence
  that MethodA cannot change parameters with effect outside its scope.



  [Non-text portions of this message have been removed]





  Yahoo! Groups Sponsor
  ADVERTISEMENT
  click here
<http://rd.yahoo.com/SIG=129mj9c75/M=298184.5022502.6152625.3001176/D=groups
/S=1705006764:HM/EXP=1086428110/A=2164339/R=0/SIG=11e2d64in/*http:/www.netfl
ix.com/Default?mqso=60183348>

<http://us.adserver.yahoo.com/l?M=298184.5022502.6152625.3001176/D=groups/S=
:HM/A=2164339/rand=629612713>

    _____

  Yahoo! Groups Links
  *      To visit your group on the web, go to:
        http://groups.yahoo.com/group/development-axapta/

  *      To unsubscribe from this group, send an email to:
        [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>

  *      Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .


  [Non-text portions of this message have been removed]



        Yahoo! Groups Sponsor
              ADVERTISEMENT





----------------------------------------------------------------------------
--
  Yahoo! Groups Links

    a.. To visit your group on the web, go to:
    http://groups.yahoo.com/group/development-axapta/

    b.. To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

    c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



[Non-text portions of this message have been removed]



Yahoo! Groups Sponsor
ADVERTISEMENT
click here


Yahoo! Groups Links

Reply via email to