PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Passing Array{all} to an object in NEW()  (Read 530 times)

Peter.Higgins

  • Diamond Member
  • *****
  • Posts: 100
    • View Profile
Passing Array{all} to an object in NEW()
« on: November 22, 2021, 06:46:22 PM »
I want to short cut opening a massive array structure in numerous objects by opening it in a main program and passing it via the new instantiation command as an parameter argument.  Thought I'd seen it here, but not finding it now.  Is it necessary to do this through a method or am I doing something wrong?  Getting sent to delete on an error 46 before the escape line immediately after on_create:  This is in Version 2017 so perhaps I'm pre versioning code?
Thanks for any help.

Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3594
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Passing Array{all} to an object in NEW()
« Reply #1 on: November 23, 2021, 10:30:37 AM »
Seems to work for me here on version 17.00. 
Personally though, I would simply use a global variable for the array to avoid having to pass it around all the time.

Here is my test:

Object:
->load "a.pvc
->list
0010 DEF CLASS "a"
0020 PROPERTY name$
0030 FUNCTION dump()
0040 DUMP
0050 RETURN
0060 END DEF
0070 on_create:
0080 ENTER val1$,arry${ALL}
0090 PRINT "In object creation"
0100 PRINT arry${ALL}
0110 LET arry$[2,2]="two-two"
0120 EXIT


Program:
->load "nov23
->list
0010 BEGIN
0020 DIM a$[1:2,1:3]
0030 FOR i=1 TO 2
0040 FOR j=1 TO 3
0050 LET a$[i,j]="<"+STR(i)+","+STR(j)+">"
0060 NEXT
0070 NEXT
0080 PRINT a${ALL}
0090 PRINT "Heading to object"
0100 LET oId=NEW("a","Test",a${ALL} FOR PROGRAM)
0110 PRINT "Back from object"
0120 PRINT a${ALL}
0130 END


Test run:
PxPlus-2020 Web (Ver:17.00/MS-WINDOWS) Serno:1700-001-xxxxxxx
(c) Copyright 2005-2020 PVX Plus Technologies Ltd. (All rights reserved)
  Website: http://www.pvxplus.com
->run "nov23
<1,1><1,2><1,3><2,1><2,2><2,3>
Heading to object
In object creation
<1,1><1,2><1,3><2,1><2,2><2,3>
Back from object
<1,1><1,2><1,3><2,1>two-two<2,3>


Peter.Higgins

  • Diamond Member
  • *****
  • Posts: 100
    • View Profile
Re: Passing Array{all} to an object in NEW()
« Reply #2 on: November 23, 2021, 10:49:20 AM »
Thanks Mike,

Will test with this. Main difference is my array is the first and only parameter if that makes a difference.

Agree with using startup global variables in objects such as company etc.

Sage initially used a number of non startup global variables in their objects and it turned into a royal pain to figure out why things weren't working despite being compliant with documentation.  Like those flags, this array is not global so the person who eventually follows me will not know that right away and the learning curve is pretty steep as is.

Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3594
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Passing Array{all} to an object in NEW()
« Reply #3 on: November 23, 2021, 10:59:13 AM »
Peter

I just tested it with the array being the only parameter and it worked fine.



Peter.Higgins

  • Diamond Member
  • *****
  • Posts: 100
    • View Profile
Re: Passing Array{all} to an object in NEW()
« Reply #4 on: November 23, 2021, 01:06:16 PM »
Mike,

My testing worked as well.  But the error 46 persisted even after changing out the array for the three strings needed. Turned out to be a property declaration where I got creative awhile back and decided to test returning a local variable rather than using a get & label.  Obviously never got to the test part.