How do I pass an array by reference and get back all modifications to the array (including subscript additions)
I have a routine tag that takes an argument and I want this argument to be an array reference. So I try something like:
do mytag(.myarr)
The mytag tag, adds subscripts to myarr.
When I evaluate myarr after the tag call, only the subscripts passed in are retained in myarr. The subscripts added by mytag are missing. Is there a way to pass an array so it will behave the way I want it to?
Comments
What's the definition of mytag? Is it using ByRef? If not, you'll want to add it.
ByRef is flavor text.
Unable to reproduce. Here's my test routine:
ByRef
kill a
set a = 1
set a(1) = 2
do Test(.a)
zw a
Test(a)
set a(1) = a(1) + 1
set a(2) = -1And here's an invocation result:
>d ^ByRef
a=1
a(1)=3
a(2)=-1as you can see a new subscript has been added successfully.
Are you doing something like 'new myarr' in mytag? That would behave as you described.
I was passing the wrong number of arguments. Totally a syntax error on my part. Thanks for the replies.
I would have responded with a similar option:
classmethod ABC(byref p1 as %String(MAXLEN=*)) as %Status
set tSC=$$$OK
try {
if $g(p1("{some_attribute_name}")) set .....
set p1("{a_new_node"})="{a_value}")
}
...
But if you wanted to keep it in proper objects pass in p1, byref, as a %ListOfDataTypes or %ListOfObjects or %ArrayOfDataTypes or %ArrayOfObjects depending on whether you are passing in an ordered list or and subscripted array