Microsoft KB Archive/268847

= PRB: Assign Method and Optimistic Buffering Makes GetFldState = 2 =

Article ID: 268847

Article Last Modified on 8/27/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q268847



SYMPTOMS
The GetFldState value for the record of a buffered table has changed to 2 - (Field has been edited or deletion status has changed). This behavior occurs when any of the data controls on the form are based on a class where an Assign method has been added for the Value property (resulting in a Value_Assign method), and the ControlSource property of the data control is set to a field of a buffered table.



CAUSE
Any Assign method contains the following code by default: LPARAMETERS vNewVal THIS.Value = m.vNewVal This code assigns the value passed into the Assign method (vNewVal) to be that of the Value property of the data control. Because the data control is bound to the table through the ControlSource property, then the data in the table is re-written even though it is the same value. This can be verified by checking the GetFldState return value of the bound field.
 * To do: Modify this routine for the Assign method



STATUS
This behavior is by design.



MORE INFORMATION
The ability to create an Assign method for the property of an object is new to Microsoft Visual FoxPro 6.0. An Assign method can be created in the following ways:
 * For intrinsic properties or existing custom properties:

Use either the Class or Form Designer interface to add a new method that consists of the name of a property followed by the suffix &quot;_Assign&quot; (without the quotes).


 * For non-existing custom properties:

Use either the Class or Form Designer interface so that the developer can click the Assign method check box while adding a new property. This creates a new method that consists of the name of the newly added property followed by the suffix &quot;_Assign&quot; (without the quotes).


 * Classes defined by program code:

Use the following naming convention rule for an Assign method because it always applies: The Assign method starts with the name of the applicable property and is followed by the suffix &quot;_Assign&quot; (without the quotes).

Once an Assign method has been created, it is impossible to circumvent it during run time when any attempt is made to write data to the property for which it was established. Also note that commenting or removing the Assign method's code results in errors. The only means by which the affects of an Assign method can be eliminated are to rename it or delete it.

The following code displays the value of GetFldState in the parent code when the Value_Assign method fires. The GetFldState value can also be checked by clicking the Command bottom labeled &quot;Get Field State.&quot;

Steps to Reproduce Behavior
  Create and run a new program with the following code: PUBLIC ox ox=CREATEOBJECT(&quot;frmGetFieldState&quot;) ox.show

DEFINE CLASS BaseText AS TextBox Height = 23 Width = 100 Value = &quot;&quot; Name = &quot;BaseText&quot;

PROCEDURE Value_Assign LPARAMETERS vNewVal *To do: Modify this routine for the Assign method Wait window &quot;In parent assign&quot; timeout 1 THIS.Value = m.vNewVal WAIT WINDOW TRANSFORM(GetFldState(&quot;cust_id&quot;)) TIMEOUT 1 ENDPROC ENDDEFINE

DEFINE CLASS frmGetFieldState AS Form Top = 65 Left = 194 Height = 87 Width = 251 DoCreate = .T.   Caption = &quot;frmGetFieldState&quot; Name = &quot;Form1&quot;

ADD OBJECT cmdRefresh AS CommandButton WITH ; Top = 48, ; Left = 17, ; Height = 27, ; Width = 90, ; Caption = &quot;Refresh&quot;, ; Name = &quot;cmdRefresh&quot;

ADD OBJECT cmdGetFieldState AS CommandButton WITH ; Top = 48, ; Left = 149, ; Height = 27, ; Width = 90, ; Caption = &quot;Get Field State&quot;, ; Name = &quot;cmdGetFieldState&quot;

ADD OBJECT txtBaseClass AS BaseText WITH ; ControlSource = &quot;customer.cust_id&quot;, ; Left = 75, ; Top = 12, ; Name = &quot;txtBaseClass&quot;

PROCEDURE Load OPEN DATABASE HOME(2)+&quot;data\testdata.dbc&quot; SHARED USE customer IN 0 SET MULTILOCKS ON       =CURSORSETPROP(&quot;Buffering&quot;,5) ENDPROC

PROCEDURE Unload USE IN customer CLOSE DATABASE ENDPROC

PROCEDURE cmdRefresh.Click ThisForm.Refresh ENDPROC

PROCEDURE cmdGetFieldState.Click WAIT WINDOW TRANSFORM(GetFldState(&quot;cust_id&quot;)) TIMEOUT 1 ENDPROC ENDDEFINE NOTE: The Assign method, Value_Assign runs when the form is initialized.

 Click the Get Field State button to display the current value of GetFldState. Click the Refresh button and note that the Assign method is called and that GetFldState = 2.

