Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scattered Variables losing scope - Help!

Status
Not open for further replies.

castor2003

Programmer
Jul 5, 2003
115
LC
Something strange is happening to me which has cost me two nights of sleep.

I have this form with a CUSTOM VCR, with next,prev btns etc. I have a 'blockaction' method on that container that references the parent Form for Next,Add and all actions. The other method of that Vcr Container is a 'myrefresh' that tests the states of the containing buttons to enable and disable accordingly. This combination works fine in cases where I am using a single page form.
I am now using it on a two-page form.

When I issue the SCATTER I was hoping, like obtains in the single page form, that the created variables(m.photo etc) would be visible everywhere. Some how the the (m.) variables related to the page textbox controls are losing range when I come to Validating their contents before GATHERING them. The Save routine is run from a custom method of the Parent form.

What are the likely cause of this problem? When I trace the code, it seems to be losing scope at the point when command leaves the 'myrefresh' method of the VCR container and returns to the 'blockaction' method. The 'Blockaction' method is called from clicking on the buttons on the VCR container.

Does it have to do with the fact that I am using multi-pages on the form? Also, the form uses Private Data.

 
I suspect what is happening is that the memory variables are being scattered in the library (vcx) and they are not public variables.

You may try scattering to an object name that is public. In other words, define it public in the startup.prg

Public goData && global object data

In the library scatter using this:

Select employee
SCATTER NAME goData



Jim Osieczonek
Delta Business Group, LLC
 
Initially I found it to be the perfect solution to my problem. But the downside is that memo fields are excluded from the created object's properties.
 
Your initial diagnosis seems not to be the case, since the variables are in scope after clicking on the 'Add' button, the form's method SCATTERS then control goes back to the VCR container for a 'myrefresh' the control goes back home to the 'BlockAction' method of the VCR. It is only on this return that the 'blockaction' method that the scope get lost. However, it was fully visible in the 'myrefresh' method. This is very confusing.
 
Try

SCATTER MEMVAR MEMO NAME oData



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
I don't know if you have a container in your vcx file, but I usually create one so I can store properites and methods inside it. In my startup app, I create a global object and referece it.

For example. The vcx has a container named "capp"

Add a property called myData

In the startup program create a global memory variable, let's call it goApp (global object App)

Startup code:
PUBLIC goApp
goApp = CREATEOBJECT('capp')

You can scatter to the global object property of the goApp ojbect, thus making it a nested object.


SCATTER MEMVAR NAME goApp.myData

There are various ways to address the problem, but if you're running into problems with it losing focus I would keep it defined in the startup program either as a global memory variable (first example I gave) or as a property on a global object. I am not sure why you're losing the memory variable, but either of these solutions should solve the problem.





Jim Osieczonek
Delta Business Group, LLC
 
Another suggestion, a bit more consolidated, is to create a standard property on your forms (already, you're trying to have standard certain memory variables.... so this doesn't really introduce a new constraint)

So, any form using your VCR control would have a property 'oData'

The scatter would always be:

SCATTER MEMVAR MEMO NAME THISFORM.oData

And all control's ControlSource properties would be:
THISFORM.oData.FieldName

Where FieldName is replaced with the appropriate field's name.

Any time you need to get to these fields (as in your Blocker method) just refer to THISFORM.oData.FieldName

This way each form is independant (which would not be the case if you used either a global object or a property of a global object)
 
Gentlemen, you have taken my programming to a very high level. Thanks everyone for your inputs. Since I have subclassed all my controls, it will be a very small deal to implement wgcs' solution. Now my problems are over, thanks a million.

 
WGCS

I think that I may have gotten you wrong. I was testing your solution and encountered a problem with the following code.

Code:
PUBLIC oForm as Form
oForm = CREATEOBJECT('lpmodals')

SELECT mytable
GO top
SCATTER MEMVAR MEMO NAME oForm.odata
oform.Visible=.t.
? oform.odata.myfield

I have already made oData a property of the parent class. Yet I am getting a message saying unknown member oData.
 
Never mind folks, it was my error. I should not have included 'MEMVAR'. My Bad. Everything works fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top