Modifying a Data File
All of the changes discussed so far have been exclusive to the DDFs or the ActiveX memory image of the DDFs. Changing the DDFs, however, does not alter the length or structure of the actual records in the data file. To do this, you need to make use of the functions that directly affect the data file.
Changing the length of a data file is not a one-operation issue. Essentially, the data file must be destroyed and rebuilt with the new length. If this is done to an existing file, the records should be copied using two VAccess controls and a temporary file. For example:
Dim totalRecs as Integer
Dim currRec as Integer
 
'We want to read the DDFs
VAccess1.RefreshLocations = True
VAccess2.RefreshLocations = True
 
'Set up our DDFPaths
VAccess1.DdfPath = “c:\myData”
VAccess2.DdfPath = “c:\myData”
 
'Set up the tables
VAccess1.TableName = “MyTable”
VAccess2.TableName = “MyTable”
 
'Now use the memory images only
VAccess1.RefreshLocations = False
VAccess2.RefreshLocations = False
 
'Add the new field to the VAccess2 memory image using 'routine shown above
AddNewField
 
'Create the actual data file & update the DDF
'The VAccess1 memory image will not be altered
VAccess2.RefreshLocations = True
VAccess2.DdfCreateTable True
 
'Temporarily assign this table to another location
VAccess2.RefreshLocations = False
VAccess2.DdfModifyLocation “tempdata.mkd”
 
'Open the files & get the first record
VAccess1.Open
VAccess2.Open
VAccess1.GetFirst
 
'Copy the records from one to the other
totalRecords = VAccess1.TotalRecords
currRec = 0
 
While currRec < totalRecords
VAccess2.Buffer(0) = VAccess1.Buffer(0)
VAccess2.Insert 'add error handling here
VAccess1.GetNext
currRec = currRec + 1
Wend
 
VAccess1.Close
VAccess2.Close
 
'Now we have two data files – one with the old data & one 'with the new. Use language API to delete the old data 'file and rename the new data file to the old name RenameTempDataFile
'Reset the location to the correct location – don’t change 'DDF, as it should be fine already VAccess2.DdfModifyLocation VAccess1.Location
There are other modifications that can be performed directly to the index structure of the data file. These operations can be found in ActiveX Method Reference and include DdfAddIndex, DdfDropIndex, and DdfDropIndexMaintain.