Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
REDIMing an shared Array of Types in a SUB
#1
Hi 2 All

Is there a way to redim a shared array of types in a Sub?

In the following code, it looks like the Change Sub creates a new local array and then when return to main code the values changed there are lost; Is there a way to to this or I must use pointers?

Greets
Tio Bit

Code:
'$DYNAMIC
OPTION EXPLICIT

TYPE TModel
   Code AS INTEGER
   Array(0 TO 1) AS INTEGER
END TYPE

DECLARE SUB Change

DIM SHARED Model AS TModel

Model.Array( 0 ) = 5
Model.Array( 1 ) = 10

PRINT Model.Array( 0 )
PRINT Model.Array( 1 )

Change

PRINT
PRINT Model.Array( 0 )
PRINT Model.Array( 1 )
PRINT Model.Array( 2 )

END

'--------------------------
SUB Change
'--------------------------
   REDIM Model.Array(0 TO 2) AS INTEGER

   Model.Array( 0 ) = 15
   Model.Array( 1 ) = 20
   Model.Array( 2 ) = 25

END SUB
Reply
#2
Have a look at Redimensioning nested UDT arrays
Reply
#3
Field arrays can't be dynamic, as in PDS/PB and unlike VB, sorry..
Reply
#4
You could use pointers. You can make the type fields pointers to a list of integers (type "integer pointer pointer") and allocate it some memory using ALLOCATE or REALLOCATE (REALLOCATE preserves memory while resizing it.) You can then access the elements like an array (note the brackets, not parenthesis): Test->IntegerArray[44] = 3

That should work. I might've left something out... but I don't think so.
color=blue]subxero - admin at this place.[/color]
Reply
#5
Thks 2 All; I change the program to pointers; Not so difficult once you get used to it
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)