{ Range.pas } program Range; {$IfDef VER80} uses SnipTool, SnipData, SysUtils, WinTypes, WinProcs, DbiProcs, DbiTypes, DbiErrs; {$Else} uses WinTypes, WinCrt, Strings, DbiProcs, DbiTypes, DbiErrs, SnipTool, SnipData; {$EndIf} const szTblName = 'stock'; { Name of the table } szTblType = szPARADOX; { Table type to use. } {===================================================================== Code: Range(); Input: None. Return: None. Description: This example shows how to limit the accessible records within a table using ranges. ===================================================================== } var hDb: hDBIDb; { Handle to the Database } hCur: hDBICur; { Handle to the table } TblProps: CURProps; { Table Properties } pRecBufLow: pBYTE; { Record Buffer } pRecBufHigh: pBYTE; { Record Buffer } sLowRange, sHighRange: String; const uNumRecs: UINT32 = 0; { Number of records to display } fLowRange: FLOAT = 2315.0; { Lowest Stock number to display } fHighRange: FLOAT = 5313.0; { Highest Stock number to display } fLowVendRange: FLOAT = 4000.0; { Lowest Vendor Number to display } fHighVendRange: FLOAT = 6000.0; { Highest Vendor Number to display } begin Screen('*** Range Operations Example ***'); Screen(' Initializing IDAPI...'); if (InitAndConnect(hDb) <> DBIERR_NONE) then { Terminate example if } begin { Initialization fails } Screen(''); Screen('*** End of Example ***'); exit; end; Screen(' Setting the default Database directory...'); ChkRslt(DbiSetDirectory(hDb, pCHAR(szTblDirectory)), DBIERR_NONE, ' Error - SetDirectory.'); Screen(' Open 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 CloseDbAndExit(hDb); Screen(''); Screen('*** End of Example ***'); exit; end; ChkRslt(DbiGetCursorProps(hCur, TblProps), DBIERR_NONE, ' Error - GetCursorProps.'); { Allocate space for the Record Buffer } GetMem(pRecBufLow, TblProps.iRecBufSize * sizeof(BYTE)); if not Assigned (pRecBufLow) then begin Screen(' Error - Could not allocate memory.'); CloseDbAndExit(hDb); Screen(''); Screen('*** End of example ***'); exit; end; GetMem(pRecBufHigh, TblProps.iRecBufSize * sizeof(BYTE)); if not Assigned (pRecBufHigh) then begin Screen(' Error - Could not allocate memory.'); FreeMem(pRecBufLow, TblProps.iRecBufSize * sizeof(BYTE)); CloseDbAndExit(hDb); Screen(''); Screen('*** End of example ***'); exit; end; Str(fLowRange:7:2, sLowRange); Str(fHighRange:7:2, sHighRange); Screen(''); Screen(' Change the range of the table: only display records'); Screen(' which have a "Stock No" between '+ ' '+sLowRange+' and '+sHighRange+' '); ChkRslt(DbiPutField(hCur, 1, pRecBufLow, @(fLowRange)), DBIERR_NONE, ' Error - PutField.'); ChkRslt(DbiPutField(hCur, 1, pRecBufHigh, @(fHighRange)), DBIERR_NONE, ' Error - PutField.'); ChkRslt(DbiSetRange(hCur, FALSE, 0, 0, pRecBufLow, FALSE, 0, 0, pRecBufHigh, TRUE), DBIERR_NONE, ' Error - SetRange.'); ChkRslt(DbiSetToBegin(hCur), DBIERR_NONE, ' Error - SetToBegin.'); Screen(''); Screen(' Display the '+szTblName+' table...'); ChkRslt(DisplayInMemoryTable(hCur, uNumRecs), DBIERR_NONE, ' Error - DisplayInMemoryTable.'); Screen(''); Screen(' Change the range of the table: no range set'); ChkRslt(DbiResetRange(hCur), DBIERR_NONE, ' Error - SetRange.'); ChkRslt(DbiSetToBegin(hCur), DBIERR_NONE, ' Error - SetToBegin.'); Screen(' Display the '+szTblName+' table...'); ChkRslt(DisplayInMemoryTable(hCur, uNumRecs), DBIERR_NONE, ' Error - DisplayInMemoryTable.'); Screen(''); Screen(' Change to the secondary index on field two...'); ChkRslt(DbiSwitchToIndex(hCur, nil, nil, 2, FALSE), DBIERR_NONE, ' Error - SwitchToIndex.'); Str(fLowVendRange:7:2, sLowRange); Str(fHighVendRange:7:2, sHighRange); Screen(''); Screen(' Change the range of the table: only display'); Screen(' records which have a Vendor No between '+ ' '+sLowRange+' and '+sHighRange+' '); ChkRslt(DbiPutField(hCur, 2, pRecBufLow, @(fLowVendRange)), DBIERR_NONE, ' Error - PutField.'); ChkRslt(DbiPutField(hCur, 2, pRecBufHigh, @(fHighVendRange)), DBIERR_NONE, ' Error - PutField.'); ChkRslt(DbiSetRange(hCur, FALSE, 0, 0, pRecBufLow, FALSE, 0, 0, pRecBufHigh, FALSE), DBIERR_NONE, ' Error - SetRange.'); ChkRslt(DbiSetToBegin(hCur), DBIERR_NONE, ' Error - SetToBegin.'); Screen(''); Screen(' Display the '+szTblName+' table...'); ChkRslt(DisplayInMemoryTable(hCur, uNumRecs), DBIERR_NONE, ' Error - DisplayInMemoryTable.'); { Release allocated memory } FreeMem(pRecBufLow, TblProps.iRecBufSize * sizeof(BYTE)); FreeMem(pRecBufHigh, TblProps.iRecBufSize * sizeof(BYTE)); Screen(''); Screen(' Close the '+szTblName+' table...'); ChkRslt(DbiCloseCursor(hCur), DBIERR_NONE, ' Error - CloseCursor.'); Screen(' Close the Database and exit IDAPI...'); CloseDbAndExit(hDb); Screen('*** End of Example ***'); end.