{ tblopen.pas } program TblOpen; {$IfDef VER80} uses SnipTool, SnipData, SysUtils, WinTypes, WinProcs, DbiProcs, DbiTypes, DbiErrs; {$Else} uses WinTypes, WinCrt, Strings, DbiProcs, DbiTypes, DbiErrs, SnipTool, SnipData; {$EndIf} const szTblName = 'cust'; { Name of table to be opened } szTblType = szDBASE; { Type of the above table } {===================================================================== Function: TableOpen(); Description: This example shows how to open and close a table. ===================================================================== } var rslt: DBIResult; { Value returned from IDAPI functions } hDb: hDBIDb; { Handle to the database } hCur: hDBICur; { Handle to the table } begin Screen('*** Opening a Table ***'); Screen(' Initializing IDAPI...'); InitOutput; rslt := ChkRslt(DbiInit(nil), DBIERR_NONE, ' Error - Init'); if (rslt <> DBIERR_NONE) then { Check if successfull } begin Screen(''); Screen('*** End of Example ***'); CloseOutput; exit; end; { Open the standard database. Notice that we are opening the database in READWRITE mode and SHARED mode. } Screen(' Opening Standard Database...'); if (ChkRslt(DbiOpenDatabase('', nil, dbiREADWRITE, dbiOPENSHARED, nil, 0, nil, nil, hDb), DBIERR_NONE, ' Error - OpenDatabase.') <> DBIERR_NONE) then begin { Clean up since an error occured } ChkRslt(DbiExit, DBIERR_NONE, ' Error - Exit.'); Screen(''); Screen('*** End of Example ***'); CloseOutput; exit; end; Screen(' Set the directory which is used by the database...'); ChkRslt(DbiSetDirectory(hDb, pCHAR(szTblDirectory)), DBIERR_NONE, ' Error - SetDirectory.'); { Open the table. The important options are: hDb - Handle to the database of the table Paradox and dBASE use the STANDARD database szTblName - Name of the table szTblType - Type of the table - not needed if the table name contains an extension dbiREADWRITE - Open the table for both Reading and Writting DBIOPENSHARED - Open the table in shared mode - other applications can have concurrent access xltFIELD - Field values are translated from Internal Paradox types to types useable in the application. } Screen(' Opening the '+szTblName+' Table...'); if (ChkRslt(DbiOpenTable(hDb, pCHAR(szTblName), pCHAR(szTblType), nil, nil, 0, dbiREADWRITE, dbiOPENSHARED, xltFIELD, FALSE, nil, hCur), DBIERR_NONE, ' Error - OpenTable.') <> DBIERR_NONE) then begin Screen(' Close the standard database...'); ChkRslt(DbiCloseDatabase(hDb), DBIERR_NONE, ' Error - CloseDatabase.'); Screen(' Exit IDAPI...'); ChkRslt(DbiExit, DBIERR_NONE, ' Error - Exit.'); Screen(''); Screen('*** End of Example ***'); CloseOutput; exit; end; Screen(''); Screen(' The '+szTblName+' table was opened successfully!'); Screen(''); Screen(' Close the '+szTblName+' table...'); ChkRslt(DbiCloseCursor(hCur), DBIERR_NONE, ' Error - CloseCursor.'); Screen(' Close the standard database...'); ChkRslt(DbiCloseDatabase(hDb), DBIERR_NONE, ' Error - CloseDatabase.'); Screen(' Exit IDAPI...'); ChkRslt(DbiExit, DBIERR_NONE, ' Error - Exit.'); Screen(''); CloseOutput; Screen('*** End of Example ***'); end.