Below is a cut-n-paste from the old Opal newsgroup.
---------------------------------------------------
Example of using the restructure method in Paradox 8 or 9. The code takes advantage of the Customer.db table found in the Samples folder.
var
tbl Table
tcFlds TCursor
dynNewStru DynArray[] Anytype
endvar
tbl.attach( "Customer.db" ) ;Customer.db in the Samples folder
tbl.enumFieldStruct( "field_struct.db" )
tcFlds.open("field_struct.db" )
tcFlds.edit()
scan tcFlds :
if tcFlds."Field Name" = "Name" then
tcFlds."Field Name" = "Company Name"
quitLoop
endif
endscan
;//delete Phone field from Customer table
scan tcFlds :
if tcFlds."Field Name" = "Phone" then
tcFlds.deleteRecord()
quitLoop
endif
endscan
;//insert field Test before the Country field
scan tcFlds :
if tcFlds."Field Name" = "Country" then
tcFlds.insertBeforeRecord()
tcFlds.(1) = "Test" ;field name
tcFlds.(2) = "ALPHA" ;field type
tcFlds.(3) = 10 ;size
quitLoop
endif
endscan
;//add field Test2 at the end of table
tcFlds.end()
tcFlds.insertAfterRecord()
tcFlds.(1) = "Test2" ;field name
tcFlds.(2) = "ALPHA" ;field type
tcFlds.(3) = 10 ;size
tcFlds.endEdit()
tcFlds.close()
dynNewStru["FIELDSTRUCT"] = "field_struct.db"
tbl.restructure( dynNewStru )
{Invalid array of validity check descriptors in most cases means that the
table structure has been changed by inserting a column anywhere but as the
last column. When you do, field name references sometimes refers to another
column than the one you expect. Try to Rebuild the table.
Anytime you change the structure of a table by removing columns and adding
columns, rebuild the table. The only valid place for a new column is as the
last column.
runExpert( "CoreUI", "TableRepair"

}
-----------------------------------------------
Mac
Mac
"Strange women lying in ponds and distributing swords is no basis for a system of government" - Dennis, age 37
mailto:langley_mckelvy@cd4.co.harris.tx.us