Bruce R. Roland
2008-12-04 23:12:14 UTC
Hello All!
Hoping someone can give me some insight as to why two variables I use won't work if they are declared local but will if declared Public.
We had some discussion on the use of Public variables vs. Local over the past week or two here in the newsgroup. From that discussion I concluded that the variables I am using in most of my programs could, in fact, and should be, in fact, declared as local rather than public. Thus, I changed the declaration of these variables from public to local.
With the exception of two of my declared variables all of them work as local rather than public variables which is what I expected of all of them after the discussion on public vs. local.
The two I had to leave as public in order for the code to work should from everything I see work if declared as local - but as said they don't.
The code for the form in which these are used is laid out below. The two variables in question are only used in the form in which they are declared - nowhere else in my code.
The only thing I can reasonably come up with for this problem is that these two are used outside the CLASS even though used on the form containing the class.
Anyone have anything that may help me understand this?
Notes:
Originally only "DisplaynhtpInvoice" was declared local - all others were declared as Public.
The obvious two variables to which I refer here as giving me a problem - if it actually is a problem - are the two declared Public in the sample code below.
Thanks.
Bruce
***********************************************************
Code sample
***********************************************************
LOCAL DisplaynhtpInvoice,;
ofields,;
nID_Ref,;
cExpn_Field_Ref,;
cInvoice_Field_Ref,;
cTotal_Field_Ref,;
oInvoice_Object_Ref,;
oTotal_Object_Ref,;
cInvoice_Value,;
cExpn_Value,;
cTotal_Value,;
nCalculated_Invoice,;
nCalculated_Expenses,;
nCalculated_Wages,;
nCalculated_Total
PUBLIC cEnabled_Ref,;
cPicture_Ref
cEnabled_Ref := "_Data.ENABLED"
cPicture_Ref := "_Data.PICTURE"
DisplaynhtpInvoice = NEW DisplaynhtpInvoice()
IF (Modal)
DisplaynhtpInvoice.MDI = false
DisplaynhtpInvoice.READMODAL()
ELSE
DisplaynhtpInvoice.MAXIMIZE := false
DisplaynhtpInvoice.MINIMIZE := false
DisplaynhtpInvoice.OPEN()
ENDIF
CLASS DisplaynhtpInvoice OF Form_TemplateFORM FROM Aims.prg
//////////////////////////////////////////////////////////////////////////////////
///// Class object definitions are here//////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
FUNCTION fSet_Params_Setup
oFields = FORM.qNhtp_Invoice.ROWSET.FIELDS
oParentTree = "FORM."
cInvoice_Field_Ref := "Invoice_No_" + n
oInvoice_Object_Ref := oParentTree + "deoInvoice_No_"
oTotal_Object_REF := oParentTree + "deoTotal_Charges_"
oTotal_Object_Ref += n + cEnabled_Ref
oInvoice_Object_Ref += n + cPicture_Ref
FUNCTION fSet_Params_Onedit
FOR n = 1 TO 14
FORM.Fset_Params_Setup()
&oTotal_Object_Ref := false
&oInvoice_object_Ref := "AA-####"
NEXT
// Ensure save() fires even when no changes occur during
// edit - (ENABLED parameters reset upon the rowset being
// saved when exiting from the edit mode (rowset ONSAVE()
// is called). If no changes made MODIFIED is false and no
// save occurs, hence no reset of ENABLED parameters. By
// setting MODIFIED to true a save is forced even if no
// changes occur ensuring ENABLED parameters are reset).
FORM.qNhtp_Invoice.ROWSET.MODIFIED = true
FUNCTION fSet_Params
FOR n = 1 TO 14
FORM.Fset_Params_Setup()
&oTotal_Object_Ref := true
IF oFields[cInvoice_Field_Ref].VALUE == "" or oFields[cInvoice_Field_Ref].VALUE = NULL
&oInvoice_Object_Ref := NULL
ENDIF
NEXT
ENDCLASS
***********************************************************
End Code sample
***********************************************************
Hoping someone can give me some insight as to why two variables I use won't work if they are declared local but will if declared Public.
We had some discussion on the use of Public variables vs. Local over the past week or two here in the newsgroup. From that discussion I concluded that the variables I am using in most of my programs could, in fact, and should be, in fact, declared as local rather than public. Thus, I changed the declaration of these variables from public to local.
With the exception of two of my declared variables all of them work as local rather than public variables which is what I expected of all of them after the discussion on public vs. local.
The two I had to leave as public in order for the code to work should from everything I see work if declared as local - but as said they don't.
The code for the form in which these are used is laid out below. The two variables in question are only used in the form in which they are declared - nowhere else in my code.
The only thing I can reasonably come up with for this problem is that these two are used outside the CLASS even though used on the form containing the class.
Anyone have anything that may help me understand this?
Notes:
Originally only "DisplaynhtpInvoice" was declared local - all others were declared as Public.
The obvious two variables to which I refer here as giving me a problem - if it actually is a problem - are the two declared Public in the sample code below.
Thanks.
Bruce
***********************************************************
Code sample
***********************************************************
LOCAL DisplaynhtpInvoice,;
ofields,;
nID_Ref,;
cExpn_Field_Ref,;
cInvoice_Field_Ref,;
cTotal_Field_Ref,;
oInvoice_Object_Ref,;
oTotal_Object_Ref,;
cInvoice_Value,;
cExpn_Value,;
cTotal_Value,;
nCalculated_Invoice,;
nCalculated_Expenses,;
nCalculated_Wages,;
nCalculated_Total
PUBLIC cEnabled_Ref,;
cPicture_Ref
cEnabled_Ref := "_Data.ENABLED"
cPicture_Ref := "_Data.PICTURE"
DisplaynhtpInvoice = NEW DisplaynhtpInvoice()
IF (Modal)
DisplaynhtpInvoice.MDI = false
DisplaynhtpInvoice.READMODAL()
ELSE
DisplaynhtpInvoice.MAXIMIZE := false
DisplaynhtpInvoice.MINIMIZE := false
DisplaynhtpInvoice.OPEN()
ENDIF
CLASS DisplaynhtpInvoice OF Form_TemplateFORM FROM Aims.prg
//////////////////////////////////////////////////////////////////////////////////
///// Class object definitions are here//////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
FUNCTION fSet_Params_Setup
oFields = FORM.qNhtp_Invoice.ROWSET.FIELDS
oParentTree = "FORM."
cInvoice_Field_Ref := "Invoice_No_" + n
oInvoice_Object_Ref := oParentTree + "deoInvoice_No_"
oTotal_Object_REF := oParentTree + "deoTotal_Charges_"
oTotal_Object_Ref += n + cEnabled_Ref
oInvoice_Object_Ref += n + cPicture_Ref
FUNCTION fSet_Params_Onedit
FOR n = 1 TO 14
FORM.Fset_Params_Setup()
&oTotal_Object_Ref := false
&oInvoice_object_Ref := "AA-####"
NEXT
// Ensure save() fires even when no changes occur during
// edit - (ENABLED parameters reset upon the rowset being
// saved when exiting from the edit mode (rowset ONSAVE()
// is called). If no changes made MODIFIED is false and no
// save occurs, hence no reset of ENABLED parameters. By
// setting MODIFIED to true a save is forced even if no
// changes occur ensuring ENABLED parameters are reset).
FORM.qNhtp_Invoice.ROWSET.MODIFIED = true
FUNCTION fSet_Params
FOR n = 1 TO 14
FORM.Fset_Params_Setup()
&oTotal_Object_Ref := true
IF oFields[cInvoice_Field_Ref].VALUE == "" or oFields[cInvoice_Field_Ref].VALUE = NULL
&oInvoice_Object_Ref := NULL
ENDIF
NEXT
ENDCLASS
***********************************************************
End Code sample
***********************************************************