>I am using VFP5.0a.
>I have a form with several textbox's tied to Table1 and a grid tied to Table2, with buffermode=2 (Optimistic).
>My Add and Edit buttons have a 'Begin Transaction' and the Revert button has 'Rollback'.
>The Save button with the following code:
>if TableUpdate()
> end transaction
>else
> **other code
>endif
>
>The problem is, when Saveing, changes to table1 fields are written, table2 changes are lost as soon as it is closed. I solved the problem by issuung:
>=TABLEUPDATE(1, .T., 'Table2')
>
>1. Why is this necessary? Is this because Table2 is in a Grid?
>
No, because the table is table-buffered, no changes are recorded to the table until a TABLEUPDATE() is issued against the table. IOW, you've updated the buffer, and until; you commit the buffer, the data is purely local, and if you decide not to keep the changes, you have the option of issuing a TABLEREVERT() instead.
>2. If this is necessary, I want to add something like the following to my class that includes my Add, Edit, Save, and Revert buttons similar to:
>for ct=1 to NumberOfTablesInDataenvironment
> =TABLEUPDATE(1, .T., 'Table'+ct')
>endfor
>How do I determine the Number of and the Name of each table in the DataEnvironment?
First, you only want to issue TABLEUPDATE() when the decision to commit the data is made (the Click of the Save), and would want to issue TABLEREVERT() in the REVERT button.
Since you won't know how many areas are open, or which areas might be in use, you'd have to do something like thefollowing code. It's terrible technique.
LOCAL i,lcInAlias
lcInAlias = ALIAS()
FOR i = 1 TO 1000
IF ! EMPTY(ALIAS())
TABLEUPDATE(1,.t., ALIAS())
ENDIF
ENDFOR
IF ! EMPTY(lcInAlias)
SELECT (lcInAlias)
ELSE
SELECT 0
ENDIF
That's indicative of a horrible lack of understanding of what data can and should be allowed to change. You migth want to considr using one of the commercial frameworks like Visual MaxFrame, ProMatrix, Mere Mortals, etc. which make provisions for handling buffered data in forms properly
Better yet, but Jim Booth and Steve Sawyer's book
Effective Techniques for Application Development using Visual FoxPro 6.0, published by Hentzenwerke (they advertise here on UT.) It's a great book, and goes into considerable detail about managing the data environment and designing good VFP apps.
>
>Thanks, Denis