SCATTER/GATHER  
Author Message
dni





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

Hou can I "scatter" in a method (valid) and "gather" in other method(click).My vf.7 is forgetting all "m." variables between methods.

Thanks,

Daniel




Visual FoxPro2  
 
 
CetinBasoz





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

thisform.addproperty("oRecord")

scatter name thisform.oRecord memo

However check buffering. In VFP you might do such things w/o scatter/gather.


 
 
dni





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

Thanks I will try, but I used thisform.refresh and worked fine.

Daniel



 
 
Dan Freeman





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

You are missing something VERY basic about memory variable scoping.

Unless it's declared PUBLIC (a bad idea), a variable is scoped to the procedure (method) that declares it and possibly called procedures (if PRIVATE).

When a method that creates a variable ends, the variable goes out of scope and is released.

A far better mechanism for making values available across all form methods is to create a property of the form. (From the Form menu, choose New Property.)

 
 
dni





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

I tried but gather is not working...



 
 
Tracy H





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

Did you check buffering as others suggested At the end of the method, what are the table values Are they stored at all and then perhaps dissappear later (after the form is closed or the table closed or the record pointer moved)

I recommend you research the solution examples. Lookup solutions under vfp help.

Or look for some tutorials online such as this one:

http://www.alvechurchdata.co.uk/fox101intro.htm


 
 
dni





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

Yes.The values are ok at the end of method.Sometimes I have the values in other method using "refresh", but today no.

 
 
Tracy H





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

When do the values dissappear then   If the values are correct immediately after your gather in the method where you issue gather, then look at the buffering.  Just to verify, are you working with tables and not a view   You don't create the table using SELECT... do you
 
 
dni





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

The ideea is: I like to do gather in other method (for example a click method(when I press a save button)).I don't know to create a table using "SELECT"!! .I am working with tables. I have very much operations between fields to use buffering and too manny databases opened.



 
 
Lakshminarayana





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

suppose if u have a table

name,add1,add2,city

scatter memvar puts the values of the fields into variables m.name,m.add1,m.add2,m.city

then append blank, gather memvar will put the values of these memory variables into newly added record in table.



 
 
dni





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

Yes you right.The problem is: visual fox forget those values(m.name,...etc) when I am running an other method(procedure).

 
 
Alex Feldstein





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

Visual FoxPro doesn't "forget" these values. Technically they go out of scope which is not the same. You have to understand scope, as explained above. To be in scope the best option is to save (or scatter) them to properties of an object (also shown above).

Instead of memory getting released when the method vars go out of scope, they get released when the object gets destroyed. This is an important concept to understand in OOP.


 
 
dni





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

My opinion is: This is a visual fox limitation. You can declare a variabile as "PUBLIC" in "INIT" and can use it over all scopes, until release it or release form. Scatter/Gather should work in the same mode.(If I am using 10 databases and I am doing 10 "scatter" I will "charge" my form with 10 objects.

Thanks for all answers



 
 
Garrett Fitzgerald





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

My opinion is: This is a visual fox limitation. You can declare a variabile as "PUBLIC" in "INIT" and can use it over all scopes, until release it or release form. Scatter/Gather should work in the same mode.(If I am using 10 databases and I am doing 10 "scatter" I will "charge" my form with 10 objects.

Actually, SCATTER/GATHER does use existing variables, given the chance.

CREATE CURSOR fred (cField1 C(1))
INSERT INTO fred VALUES ("A")
INSERT INTO fred VALUES ("B")
INSERT INTO fred VALUES ("C")
INSERT INTO fred VALUES ("D")
INSERT INTO fred VALUES ("E")

DO Proc1
DO Proc2

DO Proc3
DO Proc4
RELEASE oFred

oFred = 0
DO Proc1
DO Proc2


PROCEDURE Proc1
SCATTER NAME oFred
ENDPROC

PROCEDURE Proc2
ON ERROR MESSAGE()
oFred.cField1
ON ERROR
ENDPROC

PROCEDURE Proc3
PUBLIC oFred
SCATTER NAME oFred
ENDPROC

PROCEDURE Proc4
ON ERROR MESSAGE()
oFred.cField1
ON ERROR
ENDPROC


 
 
Tamar E. Granor





PostPosted: Visual FoxPro General, SCATTER/GATHER Top

It's not a limitation, it's a change. In FP2.x, when you created variables in the Setup of a form, you were doing so at the top of a calling chain. Those variables were scoped to the form. The VFP equivalent of a variable scoped to the form is a property.

The real problem here is that you're trying to apply a FP2.x strategy to VFP. Scatter/Gather is not the best way to handle input in VFP. Buffering is easier to use and VFP is designed to use it.

Tamar