{ rdolock.pas } program RdOLock; {$IfDef VER80} uses SnipTool, SnipData, SysUtils, WinTypes, WinProcs, DbiProcs, DbiTypes, DbiErrs; {$Else} uses WinTypes, WinCrt, Strings, DbiProcs, DbiTypes, DbiErrs, SnipTool, SnipData; {$EndIf} const szTblName = 'customer'; { Name of table to be opened } szTblType = szPARADOX; { Type of the above table } {===================================================================== Function: RdoLock(); Description: This example shows how to make a directory read-only. A directory is made read-only by calling the DbiAcqPersistTableLock function with the fully qualified pathname of the directory to lock. The 'filename' that is locked is PARADOX.DRO, which IDAPI interprets as making the directory read-only (no file named PARADOX.DRO should exist). Note: Local Share needs to be set to 'TRUE' in IDAPI.CFG in order for this example to work. ===================================================================== } var rslt: DBIResult; { Value returned from IDAPI functions } hDb: hDBIDb; { Handle to the database } hCur: hDBICur; { Handle to the table } szLockName: array[0..DBIMAXPATHLEN] of CHAR; begin Screen('*** Making a directory read-only ***'); Screen(' Initializing IDAPI...'); if (InitAndConnect(hDb) <> DBIERR_NONE) then { Terminate example if } begin { Initialization fails } Screen('*** End of Example ***'); exit; end; ChkRslt(DbiSetDirectory(hDb, pCHAR(szTblDirectory)), DBIERR_NONE, ' Error - SetDirectory.'); { Specify the directory to lock } MakeFullPath(szLockName); StrCat(szLockName, '\paradox.dro'); { Mark the directory as read only. Note that the type of the lock has to be set to 'PARADOX'. } ChkRslt(DbiAcqPersistTableLock(hDb, szLockName, pCHAR(szTblType)), DBIERR_NONE, ' AcqPersistTableLock.'); Screen(' Opening the '+szTblName+' table for Read/Write...'); Screen(' Expect error - directory read only...'); 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(' Table opened in Read/Write mode - make certain local'+ ' share is TRUE in IDAPI.CFG'); Screen(' in order to make a local directory read-only'); ChkRslt(DbiCloseCursor(hCur), DBIERR_NONE, ' Error - CloseCursor.'); end; Screen(''); Screen(' Opening the '+szTblName+' Table for Read only...'); if (ChkRslt(DbiOpenTable(hDb, pCHAR(szTblName), pCHAR(szTblType), nil, nil, 0, dbiREADONLY, dbiOPENSHARED, xltFIELD, FALSE, nil, hCur), DBIERR_NONE, ' Error - OpenTable.') <> DBIERR_NONE) then begin ChkRslt(DbiRelPersistTableLock(hDb, szLockName, pCHAR(szTblType)), DBIERR_NONE, ' RelPersistTableLock.'); CloseDbAndExit(hDb); Screen('*** End of Example ***'); exit; end; Screen(' Display the first ten records in the table...'); DisplayTable(hCur, 10); Screen(''); Screen(' Close the '+szTblName+' table...'); ChkRslt(DbiCloseCursor(hCur), DBIERR_NONE, ' Error - CloseCursor.'); { Release the read-only lock on the directory } ChkRslt(DbiRelPersistTableLock(hDb, szLockName, pCHAR(szTblType)), DBIERR_NONE, ' RelPersistTableLock.'); Screen(' Close the Database and exit IDAPI...'); CloseDbAndExit(hDb); Screen('*** End of Example ***'); end.