PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV 2024 → [WD21]Passing array between 2 windows
[WD21]Passing array between 2 windows
Started by Ericus, Aug., 13 2018 5:20 PM - 6 replies
Posted on August, 13 2018 - 5:20 PM
Hi

In one page I have a small Structure defined as below.

STStores is Structure
StoreCode is string
Description is string
VCode is string
END
gstRecStores is STStores
garrStores is array of STStores

I fill with a few entries and all is fine. I want to pass this array to a new window, where the number of entries in the array can be increased or decreased.

How do I go about passing this array backwards and forwards between the 2 Windows? The way I am doing it now, the array, once received in the 1st window, has lost a bit of it's readability i.e. StoreCode on some lines are suddenly empty.

Thanks in advance for your assistance.



Ericus Steyn
Registered member
4 messages
Popularité : +1 (1 vote)
Posted on August, 13 2018 - 6:37 PM
Hi Ericus,

You didn't provide how you currently pass the array to the window, but this is how I would do it.

Project Declaration:
// Strucure in the project declaration so that all elements of your code have access to it
STStores is structure
StoreCode is string
Description is string
VCode is string
END


Code of first window:
// Window initialisation
// I'd avoid using a global variable for RecStores. I don't know what your use is with this variable but you should not use it to manipulate data in the array.
Procedure WIN_Window1(<params>)
garrStores is array of STStores

// ...

// Call to the second window
garrStores = Open(WIN_Window2, garrStores)

// Do stuff to the array
// ...


Code of second window:
// Window initialisation
// Note the use of the LOCAL prefix. The LOCAL prefix will create a data copy instead of a copy by address.
Procedure WIN_Window2(LOCAL garrStores)

// --- Procedure in your second window ---
// Insert another value in the array
nTemp is int = Add(garrStores)
garrStores[nTemp].StoreCode = "1234"
garrStores[nTemp].Description = "A regular store."
garrStores[nTemp].VCode = "4321"
// ...

// Exit code of your second window
MyWindow..ReturnedValue = garrStores
Close()
Message modified, August, 13 2018 - 6:38 PM
Posted on August, 14 2018 - 11:25 AM
Hi Ericus,


i used to do this with memory zones, works perfect.

not tried with arrays, but a simple solution would be to define the array as global, so you need no passing back and forward

regards, Heinz
Posted on August, 14 2018 - 11:34 AM
Thanks Heinz

No idea what a memory zone is but will define the array as a global. However I don't like to overload the global variables.

Thanks again



Ericus
Posted on August, 14 2018 - 12:01 PM
Hi Ericus,

Or you could have a class with global members.
The global declared members are shared between all instances of that class.

Cheers,

Peter Holemans
Registered member
4 messages
Popularité : +1 (1 vote)
Posted on August, 14 2018 - 2:01 PM
Peter Holemans wrote:
Hi Ericus,

Or you could have a class with global members.
The global declared members are shared between all instances of that class.

Cheers,

Peter Holemans


heinz kuebler wrote:
Hi Ericus,


i used to do this with memory zones, works perfect.

not tried with arrays, but a simple solution would be to define the array as global, so you need no passing back and forward

regards, Heinz


Peter and Heinz,

While this would work, it is not a good solution. You should always avoid using global variables and use parameters to pass values to functions and Windows.

Using a class is a great idea, but not by declaring a global array in that class. Have a private array in your class and declare a get_StoreArray and set_StoreArray procedure to manipulate the array. Using global variables is great, until someone else than you starts working on the project and has no idea why a value changes with no apparent reason and spends 2 days figuring out that the value has been changed by an external window.
Posted on August, 14 2018 - 2:17 PM
Ericus,

how is opening section of Window1 declared? I guess you have something like

PROCEDURE Window1(LOCAL MyArray is array of STStores)

The LOCAL keyword is important here, otherwise you pass the array "by reference" and as a result you will return it "to itself". Not sure if that's allowed.