This example creates a new TableDef object, adds a Field object to it, and appends the TableDef to the TableDefs collection in the current database. Then the example enumerates all the TableDef objects in the current database and all the properties of the new TableDef. See the methods and properties listed in the TableDef summary topic for additional examples.
FUNCTION Start
LOCAL dbeng AS DaoDBEngine
LOCAL db AS DaoDatabase
LOCAL tdfEnum AS DaoTableDef
LOCAL fldDate AS DaoField
LOCAL nFld, nIdx AS LONG
LOCAL oErr AS USUAL
LOCAL cbOldErr AS CODEBLOCK
Set COlor TO w+/b
cls
BEGIN SEQUENCE
cbOldErr := ErrorBlock({|oErr|_Break(oErr)})
dbEng := DaoDbengine{}
// Open the database.
db := dbEng:OpenDatabase("\VO2Jet\Northwind.mdb",NIL,NIL,NIL)
BEGIN SEQUENCE
db:TableDefs:Delete("MyTable")
END
// Create a tabledef.
tdfEnum := db:CreateTableDef("MyTable",NIL,NIL,NIL)
fldDate := tdfEnum:CreateField("Date", dbDate,NIL)
tdfEnum:Fields:Append(fldDate)
db:TableDefs:Append(tdfEnum)
// Get database name.
? "Database Name: ", db:Name
// Enumerate all fields in tdfEnum.
? "TableDef: Name; Field: Name"
FOR nFld := 1 TO tdfEnum:Fields:Count STEP 1
? tdfEnum:Name, tdfEnum:Fields:[Item,nFld]:Name
NEXT
tdfEnum := Db:TableDefs:[Item,"Customers"]
// Enumerate all indexes in tdfEnum.
? "TableDef: Name; Index: Name"
FOR nIdx := 1 TO tdfEnum:Indexes:Count STEP 1
? tdfEnum:Name, tdfEnum:Indexes:[Item,nIdx]:Name
NEXT
// Enumerate built-in properties of tdfEnum.
? "tdfEnum.Name : ", tdfEnum:Name
? "tdfEnum.Attributes : ", tdfEnum:Attributes
? "tdfEnum.Connect : ", tdfEnum:Connect
? "tdfEnum.DateCreated : ", tdfEnum:DateCreated
? "tdfEnum.LastUpdated : ", tdfEnum:LastUpdated
? "tdfEnum.RecordCount : ", tdfEnum:RecordCount
? "tdfEnum.SourceTableName: ", tdfEnum:SourceTableName
? "tdfEnum.Updatable : ", tdfEnum:Updatable
? "tdfEnum.ValidationRule : ", tdfEnum:ValidationRule
? "tdfEnum.ValidationText : ", tdfEnum:ValidationText
wait
db:TableDefs:Delete("MyTable")
RECOVER USING oErr
Eval(cbOldErr, oErr)
END