Delphi Examples: DbiSetRange

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Delphi Examples: DbiSetRange

Return to chapter overview

Set the range for the specified cursor and return the amount of records in the range.

Delphi programs should call the SetRange, ApplyRange, ResetRange methods of a TTable. This example sets the range for the specified cursor and returns the amount of records in the range. For this example to operate, the first field of the table must be numeric. such as, STOCK.DB.

This example uses the following input:

 fDbiSetRange(Table1.Handle, Count);

 

The procedure is:

procedure fDbiSetRange(hTmpCur: hDBICur; var Count: LongInt);

var

  pMinBuf, pMaxBuf: PByte;

  key_min, key_max: double;

  CurProp: CURProps;

begin

 pMinBuf := nil;

 pMaxBuf := nil;

 key_min := 1000.00;

 key_max := 2000.00;

 

 Check(DbiGetCursorProps(hTmpCur, CurProp));

 

 GetMem(pMinBuf,CurProp.iRecBufSize);

if (pMinBuf = nil) then

   Check(DBIERR_NOMEMORY);

 

 GetMem(pMaxBuf,CurProp.iRecBufSize);

if (pMaxBuf = nil) then

   Check(DBIERR_NOMEMORY);

try

   Check(DbiPutField(hTmpCur, 1, pMinBuf, @key_min));

   Check(DbiPutField(hTmpCur, 1, pMaxBuf, @key_max));

 

   Check(DbiSetRange(hTmpCur, False, 0, 0, pMinBuf, False,

     0, 0, pMaxBuf, True));

 

   // Set the return count for the number of records in the limited range

   Count := 0;

   Check(DbiGetRecordCount(hTmpCur, Count));

 

   Check(DbiResetRange(hTmpCur));

finally

   FreeMem(pMinBuf);

   FreeMem(pMaxBuf);

end;

end;