Code: Select all | Expand
oCust := TDatabase():New( , "C:\FWH\SAMPLES\CUSTOMER", "DBFCDX", .t. )
oCust:use()
if oCust:used()
oCust:first := Upper( oCust:First )
oCust:Save()
XBROWSER oCust
else
? "file not used"
endif
Could be simply:
Code: Select all | Expand
oCust := TDatabase():New( , "C:\FWH\SAMPLES\CUSTOMER", "DBFCDX", .t. )
IF oCust:use()
oCust:first := Upper( oCust:First )
oCust:Save()
XBROWSER oCust
else
? "file not used"
endif
Now this is actually still more than one needs. You could do a class tCustomer that inherits from tData, and automatically opens the file, sets the index, and is poised to position to the correct record; and the ultimate code would be:
Code: Select all | Expand
oCust := TCustomer():New( nID )
oCust:first := Upper( oCust:First )
oCust:Save()
XBROWSER oCust
In this case a new class tCustomer is created. It is called with the nID to position the record, the data is changed, and saved. Of course, since tData holds the field values in buffers they all would want to be written back, and if a field is locked, that woulde be a problem.
The value of tData is that is a class that INHERITS from tDatabase and does many things automatically. Used with tRecord, it is a safe way to edit data easily outside of the saved records, and when the changes are complete and confirmed, it then saves the values back to the actually file. Those of us who use it appreciate the benefits.