ibbm


Hi,

I have created a form to update/add info into a table depending on the actions. I use a prg file for the actual update as this routine is used in several other procedures outside this form.

in the INIT() of the screen I either do a blank screen if an add or display the record if it exists. I do this with a scatter memvar command. The objects on the forms have controlsources of m.variables. After entering the data I call 3 programs but of course the memory variables are no longer in scope. I've read about adding a property to the form and using scatter name oRecord but how do I gather the m.variables from the screen into the oRecord without having to go

This.oRecord.field1 = m.field1

This.oRecord.field2 = m.field2.

In there some quick command that will copy all my m.variables into my oRecord

Thanks in advance.




Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

Naomi Nosonovsky


Perhaps it's better forget about m. variables for now and stick with the oRecord approach in both places. Why do you need to mix and match them




Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

dni

You may declare a PUBLIC variable oYourTable then you may use in anywere :

SCATTER NAME oYourTable

GATHER NAME oYourTable







Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

ibbm

how do I set the control source to oRecord variable. In the control source I tried putting oRecord.field1 but go a unknown member

error.





Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

ibbm

I thought I read that it's best to keep away from public variables.



Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

Naomi Nosonovsky

Form's Load

thisform.AddProperty('oRecord', NULL)
SCATTER memo NAME thisform.oRecord (you can add blank)

In the properties for ControlSource just set it to be thisform.oRecord.myField. I've quickly tested it and it worked for display.





Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

Naomi Nosonovsky

Yes, don't use public variables, use form's properties instead.

Found this discussion http://fox.wikis.com/wc.dll Wiki~DisappearingPublicVars may be there are more.





Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

dni

You may use public variables because they exists.




Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

Alex Feldstein

Public variables do not belong in an OOP system. Don't use them.


What you can use instead is a global object (e.g. declaring oApp to be a global pbject)

As a simple example you could use the _screen object:

_screen.AddProperty("oTest")

scatter name _screen.oTest





Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

dni

So what All are in same computer RAM. If program crash you still can find public in RAM....




Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

ibbm

Yeah it worked... however further down the road in my procedure I seem to be missing something.

I thought I read that you can access my form from outside programs by doing

oForm = myForm.ActiveForm

then I can reference

oForm.oRecord.myfield....

but when I do this I get an error message saying ActiveForm property does not exist. When I'm in the debugger and I can see all it's objects. Do I have to set this property on MyForm before calling my update.prg





Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

Naomi Nosonovsky

Code Snippet

IF type("_screen.ActiveForm.name") = 'C' and pemstatus('oRecord', _screen.ActiveForm, 5)

you can access _screen.ActiveForm.oRecord

ENDIF





Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

Naomi Nosonovsky

dni wrote:
So what All are in same computer RAM. If program crash you still can find public in RAM....

I guess you mean if the program crashes in IDE.





Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

Alex Feldstein

dni wrote:
So what All are in same computer RAM. If program crash you still can find public in RAM....

The problem with PUBLIC variables (as defined in VFP) does not rely on security but in data encapsulation. PUBLIC breaks encapsulation and can quickly become a maintenance problem. Each method or routine should have its own set of local variables and local properties. To share information across objects you can have a global object where every method can access its properties through calling that object.

http://fox.wikis.com/wc.dll Wiki~PublicAndPrivateVariables

http://fox.wikis.com/wc.dll Wiki~DisappearingPublicVars





Re: how to gather m. variables from a form into table where it's updated in a procedure outside the form

dni

Links show nothing...Can you show a example of program crash because of public variables not confounded with parameters