|
| [WD21]Passing array between 2 windows |
| Iniciado por guest, 13,ago. 2018 17:20 - 6 respuestas |
| |
| | | |
|
| |
| Publicado el 13,agosto 2018 - 17:20 |
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 |
| |
| |
| | | |
|
| | |
| |
Miembro registrado 4 mensajes |
|
| Publicado el 13,agosto 2018 - 18:37 |
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:
STStores is structure StoreCode is string Description is string VCode is string END
Code of first window:
Procedure WIN_Window1(<params>) garrStores is array of STStores
garrStores = Open(WIN_Window2, garrStores)
Code of second window:
Procedure WIN_Window2(LOCAL garrStores)
nTemp is int = Add(garrStores) garrStores[nTemp].StoreCode = "1234" garrStores[nTemp].Description = "A regular store." garrStores[nTemp].VCode = "4321"
MyWindow..ReturnedValue = garrStores Close()
Mensaje modificado, 13,agosto 2018 - 18:38 |
| |
| |
| | | |
|
| | |
| |
| Publicado el 14,agosto 2018 - 11:25 |
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 |
| |
| |
| | | |
|
| | |
| |
| Publicado el 14,agosto 2018 - 11:34 |
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 |
| |
| |
| | | |
|
| | |
| |
| Publicado el 14,agosto 2018 - 12:01 |
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 |
| |
| |
| | | |
|
| | |
| |
Miembro registrado 4 mensajes |
|
| Publicado el 14,agosto 2018 - 14:01 |
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. |
| |
| |
| | | |
|
| | |
| |
| Publicado el 14,agosto 2018 - 14:17 |
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. |
| |
| |
| | | |
|
| | | | |
| | |
|