| Author |
sharing variables and arrays in different comboboxes in a form
|
|
| Piddepadde 2005-05-01, 8:28 pm |
| I am rewriting an application from foxpro 2.6 to vfp 9 and have some problem
to understand the way to sharr variables and arrays in different comboboxes
in the same form.
When I create an array, using SQL select command, in a "valid" method in one
combobox I can't use it (see the contents) in another combox methods.
I think that I have missed something basic...
Is there any basic, initally command that has to be set in order to use
arrays and variables trough a forms different objects... ?
/Patrik
| |
| Anders Altberg 2005-05-01, 8:28 pm |
| Any array or variable created in a procedure is scoped to that procedure and
released when that procedure finishes. A Private variable can still be seen
in a procedure called from the procedure where it was created (unless the
theres a PRIVATE declaration in the subprocedure).
Make the array a Form property or possibly a property of a combobox.
THIS.ADDPROPERTY("arr(1)")
SELECT ... INTO ARRAY This.arr
-Anders
"Piddepadde" < Piddepadde@discussio
ns.microsoft.com> wrote in message
news:C96F2CB2-A631-4850-B3A5- 2DC71B1C82E9@microso
ft.com...
> I am rewriting an application from foxpro 2.6 to vfp 9 and have some
problem
> to understand the way to sharr variables and arrays in different
comboboxes
> in the same form.
>
> When I create an array, using SQL select command, in a "valid" method in
one
> combobox I can't use it (see the contents) in another combox methods.
> I think that I have missed something basic...
>
> Is there any basic, initally command that has to be set in order to use
> arrays and variables trough a forms different objects... ?
>
> /Patrik
| |
| Piddepadde 2005-05-02, 3:25 am |
| If I declare a private array in the forms load or init method - can I use
that array in a valid method of a combobox in that form or should I declare
it somewhere else..
(think I have tested this with no success)
/Patrik
"Anders Altberg" wrote:
> Any array or variable created in a procedure is scoped to that procedure and
> released when that procedure finishes. A Private variable can still be seen
> in a procedure called from the procedure where it was created (unless the
> theres a PRIVATE declaration in the subprocedure).
> Make the array a Form property or possibly a property of a combobox.
> THIS.ADDPROPERTY("arr(1)")
> SELECT ... INTO ARRAY This.arr
>
> -Anders
>
> "Piddepadde" < Piddepadde@discussio
ns.microsoft.com> wrote in message
> news:C96F2CB2-A631-4850-B3A5- 2DC71B1C82E9@microso
ft.com...
> problem
> comboboxes
> one
>
>
| |
| Stefan Wuebbe 2005-05-02, 3:25 am |
|
"Piddepadde" < Piddepadde@discussio
ns.microsoft.com> schrieb im Newsbeitrag
news:4C33C412-DAC7-4FB1-BD69- 684D12AF0227@microso
ft.com...
> If I declare a private array in the forms load or init method - can I use
> that array in a valid method of a combobox in that form
No, that's what Anders meant saying it gets released when the
method has finished.
> or should I declare it somewhere else..
No, while you can declare it as Public, better use Anders' object.property
suggestion.
hth
-Stefan
--
|\_/| ------ ProLib - programmers liberty -----------------
(.. ) Our MVPs and MCPs make the Fox run....
- / See us at www.prolib.de or www.AFPages.de
-----------------------------------------------------------
| |
| Piddepadde 2005-05-02, 3:25 am |
| If I use thisform. addproperty('myarray
(1)') - will this array be available
throuhout all methods in the form ?
where do I put this script ?? in the forms init or load method ??
/Patrik
"Anders Altberg" wrote:
> Any array or variable created in a procedure is scoped to that procedure and
> released when that procedure finishes. A Private variable can still be seen
> in a procedure called from the procedure where it was created (unless the
> theres a PRIVATE declaration in the subprocedure).
> Make the array a Form property or possibly a property of a combobox.
> THIS.ADDPROPERTY("arr(1)")
> SELECT ... INTO ARRAY This.arr
>
> -Anders
>
> "Piddepadde" < Piddepadde@discussio
ns.microsoft.com> wrote in message
> news:C96F2CB2-A631-4850-B3A5- 2DC71B1C82E9@microso
ft.com...
> problem
> comboboxes
> one
>
>
| |
| Jack Jackson 2005-05-02, 9:24 am |
| On Mon, 2 May 2005 00:48:08 -0700, "Piddepadde"
< Piddepadde@discussio
ns.microsoft.com> wrote:
>If I use thisform. addproperty('myarray
(1)') - will this array be available
>throuhout all methods in the form ?
Yes
>
>where do I put this script ?? in the forms init or load method ??
The order of method call during form instantiation is:
Form Load
Init for all of the objects on the form
Form Init
If you need to reference the property during the Init of any form
objects, then you must create it in Load, otherwise Init would be
fine.
Rather than using AddProperty you can also create form properties at
design time.
[color=darkred]
>
>/Patrik
>
>"Anders Altberg" wrote:
>
| |
| Anders Altberg 2005-05-02, 11:24 am |
| No, you can't. Load and Init are events that have ended when you get to see
the form. Even with a lot of code they probably only exist for a one or two
seconds at most. What is your problem with using form properties? That is
the OOP way of programming.
-Anders
"Piddepadde" < Piddepadde@discussio
ns.microsoft.com> wrote in message
news:4C33C412-DAC7-4FB1-BD69- 684D12AF0227@microso
ft.com...
> If I declare a private array in the forms load or init method - can I use
> that array in a valid method of a combobox in that form or should I
declare[color=darkre
d]
> it somewhere else..
> (think I have tested this with no success)
>
> /Patrik
>
> "Anders Altberg" wrote:
>
and[color=darkred]
seen[color=darkred]
the[color=darkred]
in[color=darkred]
use[color=darkred]
| |
| Anders Altberg 2005-05-02, 11:24 am |
| You can put it in either one, Init or Load. If the combobox is going to use
it you can make it a property of the combobox itself, and set it up in the
combobox's Init. If it's going to be shared by several comboboxes, the Load
would be fine. The Form's Init happens after the comboboxes have been
initialised. An array is only one of several ways of populating a ComboBox
control.
-Anders
"Piddepadde" < Piddepadde@discussio
ns.microsoft.com> wrote in message
news:889FC08C-8E6D-46A1-94AF- F4976BCF48D4@microso
ft.com...[color=darkred]
> If I use thisform. addproperty('myarray
(1)') - will this array be available
> throuhout all methods in the form ?
>
> where do I put this script ?? in the forms init or load method ??
>
> /Patrik
>
> "Anders Altberg" wrote:
>
and[color=darkred]
seen[color=darkred]
the[color=darkred]
in[color=darkred]
use[color=darkred]
| |
| Piddepadde 2005-05-03, 7:25 am |
| Thanks all, your answers has helped me alot.. Have another question :
how to share a memvar or make it available to different objects through a form
example:
If I do following in one objects valid method
SELECT qporder
SCATTER MEMVAR MEMO
and show the contents in textfields... I have tried to use , for example
m.artno as a control source but the variable is probably realsed (just as the
arrays)
I need also to save the result in a third objects valid method using:
GATHER MEMVAR MEMO
.... how to make the MEMVAR available to all the objects in a form..?
best regards
Patrik
"Piddepadde" wrote:
> I am rewriting an application from foxpro 2.6 to vfp 9 and have some problem
> to understand the way to sharr variables and arrays in different comboboxes
> in the same form.
>
> When I create an array, using SQL select command, in a "valid" method in one
> combobox I can't use it (see the contents) in another combox methods.
> I think that I have missed something basic...
>
> Is there any basic, initally command that has to be set in order to use
> arrays and variables trough a forms different objects... ?
>
> /Patrik
| |
| Piddepadde 2005-05-03, 7:25 am |
| Thanks for all answers.. have one more question:
how to make the MEMVAR available from following line in a valid method of an
object:
SCATTER MEMVAR MEMO
how to use, for example, the field m.martno in a text field
and
GATHER MEMVAR MEMO
in another objects valid method in the same form..?
/Patrik
"Piddepadde" wrote:
> I am rewriting an application from foxpro 2.6 to vfp 9 and have some problem
> to understand the way to sharr variables and arrays in different comboboxes
> in the same form.
>
> When I create an array, using SQL select command, in a "valid" method in one
> combobox I can't use it (see the contents) in another combox methods.
> I think that I have missed something basic...
>
> Is there any basic, initally command that has to be set in order to use
> arrays and variables trough a forms different objects... ?
>
> /Patrik
| |
| Fred Taylor 2005-05-03, 11:24 am |
| Short answer is you shouldn't, because the only way to make it the variables
available to all methods of a form is to make them public.
What you should do is create a form property and use scatter name to
reference your "variables".
Say you've added a property named "oFields" to your form.
Then use SCATTER MEMO NAME thisform.oFields. You'd now reference everything
from anyplace in your form via:
thisform.oFields.field1, thisform.oFields.fieldX, etc.
--
Fred
Microsoft Visual FoxPro MVP
"Piddepadde" < Piddepadde@discussio
ns.microsoft.com> wrote in message
news:31CC72A8-A9CD-436F-AEB3- 2B08785B6CC0@microso
ft.com...[color=darkred]
> Thanks for all answers.. have one more question:
>
> how to make the MEMVAR available from following line in a valid method of
> an
> object:
>
> SCATTER MEMVAR MEMO
>
> how to use, for example, the field m.martno in a text field
>
> and
>
> GATHER MEMVAR MEMO
>
> in another objects valid method in the same form..?
>
> /Patrik
>
> "Piddepadde" wrote:
>
| |
| Piddepadde 2005-05-03, 1:24 pm |
| Hi fred,
soon I think I got it !! but not yet.....
I put this line in the init method of the form:
thisform.AddProperty("morder")
Then I put following line in a combobox valid method of the form:
SCATTER MEMO NAME thisform.morder
But get a error message "Unknown member MORDER. Unbinding object ordernr"
Ordernr is the object that contain the scatter command...
When I use thisform.morder.ordnr (ordnr is a field in my table) as a
controlsource in a textfield..
Why ??
/Patrik
"Fred Taylor" wrote:
> Short answer is you shouldn't, because the only way to make it the variables
> available to all methods of a form is to make them public.
>
> What you should do is create a form property and use scatter name to
> reference your "variables".
>
> Say you've added a property named "oFields" to your form.
>
> Then use SCATTER MEMO NAME thisform.oFields. You'd now reference everything
> from anyplace in your form via:
>
> thisform.oFields.field1, thisform.oFields.fieldX, etc.
>
> --
> Fred
> Microsoft Visual FoxPro MVP
>
>
> "Piddepadde" < Piddepadde@discussio
ns.microsoft.com> wrote in message
> news:31CC72A8-A9CD-436F-AEB3- 2B08785B6CC0@microso
ft.com...
>
>
>
| |
| Fred Taylor 2005-05-03, 8:25 pm |
| Shouldn't be. Try moving the AddProperty to the form Load instead.
--
Fred
Microsoft Visual FoxPro MVP
"Piddepadde" < Piddepadde@discussio
ns.microsoft.com> wrote in message
news:0E039517-36D6-4F0D-90D8- D698E5B725FF@microso
ft.com...[color=darkred]
> Hi fred,
>
> soon I think I got it !! but not yet.....
>
> I put this line in the init method of the form:
>
> thisform.AddProperty("morder")
>
> Then I put following line in a combobox valid method of the form:
>
> SCATTER MEMO NAME thisform.morder
>
> But get a error message "Unknown member MORDER. Unbinding object ordernr"
> Ordernr is the object that contain the scatter command...
>
> When I use thisform.morder.ordnr (ordnr is a field in my table) as a
> controlsource in a textfield..
>
> Why ??
>
> /Patrik
> "Fred Taylor" wrote:
>
| |
| Anders Altberg 2005-05-04, 1:24 pm |
| The Init of the Form comes after all contained objects have been
initialized. Thus, when the combobox tries to use thisform.morder it's not
been added yet. If you add it in the Load you'll be Ok. If you make a form
class (stored it in a ClassLibrary) and add a property called morder to this
form, then it will also be available to contained objects, just like native
form properties.
-Anders
"Piddepadde" < Piddepadde@discussio
ns.microsoft.com> wrote in message
news:0E039517-36D6-4F0D-90D8- D698E5B725FF@microso
ft.com...[color=darkred]
> Hi fred,
>
> soon I think I got it !! but not yet.....
>
> I put this line in the init method of the form:
>
> thisform.AddProperty("morder")
>
> Then I put following line in a combobox valid method of the form:
>
> SCATTER MEMO NAME thisform.morder
>
> But get a error message "Unknown member MORDER. Unbinding object ordernr"
> Ordernr is the object that contain the scatter command...
>
> When I use thisform.morder.ordnr (ordnr is a field in my table) as a
> controlsource in a textfield..
>
> Why ??
>
> /Patrik
> "Fred Taylor" wrote:
>
variables[color=dark
red]
everything[color=dar
kred]
of[color=darkred]
in[color=darkred]
use[color=darkred]
| |
| Piddepadde 2005-05-07, 7:24 am |
| Thanks to you all
/Patrik
"Anders Altberg" wrote:
> The Init of the Form comes after all contained objects have been
> initialized. Thus, when the combobox tries to use thisform.morder it's not
> been added yet. If you add it in the Load you'll be Ok. If you make a form
> class (stored it in a ClassLibrary) and add a property called morder to this
> form, then it will also be available to contained objects, just like native
> form properties.
> -Anders
>
> "Piddepadde" < Piddepadde@discussio
ns.microsoft.com> wrote in message
> news:0E039517-36D6-4F0D-90D8- D698E5B725FF@microso
ft.com...
> variables
> everything
> of
> in
> use
>
>
|
|
|
|