*In main.prg: *Open SDT PUBLIC oMeta mydir = "..\DATA" && just an example of where a dbc and meta data tables might exist oMeta = NEWOBJECT('DBCXMgr', 'DBCXMGR.VCX', '', .F., mydir) IF TYPE('oMeta') <> 'O' OR ISNULL(oMeta) * display an error message and exit, because * DBCX cannot be used =Okay('Error Opening the DBC Manager. App will exit.') RETURN ENDIF IF !USED('CUSTOMER') =UseDbf('CUSTOMER','MyDatabase','CustNo') && table=Customer, Database = MyDatabase, Order = CustNo ENDIF RETURN *********************************************************************** *In the prg that opens a table: *the u parameters are passed to this program *ufile = the filename e.g. mytable.dbf ualias is the alias name to use when opening it PROCEDURE usedbf LPARAMETERS ufile, udbc, uorder, ualias, uparm1, uparm2, uparm3, uparm4, uparm5 xreturn = .F. IF EMPTY(ufile) OR TYPE('ufile') <> "C" WAIT WINDOW 'Error in USEDBF.PRG - File name is missing from parameters. Unable to open table.' RETURN xreturn ENDIF *Set up your own checks for what is passed, these are just examples uexclu = .F. && do not open exclusively uagain = .F. && do not add 'AGAIN' usession = 1 && use the default datasession uview = .F. && its' a view not a table IF '.' $ ufile ufile = LEFT(ufile,AT('.',ufile)-1) ENDIF IF EMPTY(udbc) udbc = '' ELSE *---If the udbc contains a '\' assume it is a directory name. IF OCCURS('\', udbc) > 0 udir = udbc IF RIGHT(udir,1) <> '\' udir = udir + '\' ENDIF ENDIF ENDIF IF EMPTY(ualias) ualias = '' ENDIF ON ERROR ErrorHandler(ERROR(), MESSAGE(), LINENO()) *ufile is the .dbf, uorder is the index order, uxeclu is exclusive or not, ualias is the alias, etc... IF !EMPTY(udir) xreturn = oMeta.oSDTMgr.OpenTable(udir+ufile, uorder, uexclu, ualias, .F., usession) ELSE IF !EMPTY(udbc) oMeta.SetDatabase(udbc) ENDIF xreturn = oMeta.oSDTMgr.OpenTable(ufile, uorder, uexclu, ualias, uview, usession) ENDIF && etc RETURN xreturn PROCEDURE ErrorHandler PARAMETERS tnError, tcMessage, tnLineno DO CASE CASE tnError = 1 AND NOT EMPTY(oMeta.oSDTMgr.cAlias) *File "<file>" does not exist. DO BakUpTbl WITH oMeta.oSDTMgr.cAlias oMeta.oSDTMgr.Update(oMeta.oSDTMgr.cAlias) RETURN 'Retry' CASE INLIST(tnError, 5, 19, 20, 23, 26, 112, 114, 1124, 1683, 1707, 1567) AND NOT EMPTY(oMeta.oSDTMgr.cAlias) * If an index error occurred (5 = record out of range, 19 = index doesn't match * DBF, 20 = record not in index, 23 = index expression too big, 26 = table * isn't ordered, 112 = invalid key length, 114 = index file doesn't match DBF, * 1124 = key too big, 1683 = tag not found, 1707 = structural CDX not found, * 1567 = primary key invalid), reindex the table. oMeta.oSDTMgr.Reindex(oMeta.oSDTMgr.cAlias) RETURN 'Retry' etc...The .repair is usually like this:
OPEN database MYDatabase && Database name is MyDatabase in this example oMeta = NewObject('DBCXMgr', 'DBCXMGR.VCX') oMeta.SetDatabase(dbc()) IF ! oMeta.oSDTMgr.Repair('CUSTOMER') && Customer.dbf RETURN && an error ENDIF*Update: Look up Repair in the SDT help file under 'Stonefield Database Toolkit Class Library' It provides good examples on repairing a single table or all tables in a dbc...