FFNtxOpen - FFNtxGetCount - FFNtxGetFirst - FFNtxGetNext - FFNtxClose
NTX read routines

Prototype

Put the following prototypes in the prototypes section of the application program header file:

int   ( __stdcall *pfnFFNtxOpen )( char* );
int   ( __stdcall *pfnFFNtxGetCount)( char* );
int   ( __stdcall *pfnFFNtxGetFirst)( void );
int   ( __stdcall *pfnFFNtxGetNext)( void );
void  ( __stdcall *pfnFFNtxClose )( void );

Purpose

Search a key into a NTX file, and retrieve the record numbers in the related DBF, without using the Borland Database Engine.

Description and use

Use these 5 routines to:
  • open a NTX file
  • get the number of records with the index field matching a given key
  • get the first matching record number
  • get the successive matching record numbers
  • close the NTX file
You will then read the records with the index field matching the given key, and for this reason you might want to use this set of NTX read routines in conjunction with the set of
DBF read routines.

The returned record numbers don't care about deleted records. You should read each and any record and determine yourself whether the record is deleted or not (check the record's leading byte, being 0x20 a normal record, and 0x2A a deleted record).

See the example below to see how to use it all. You might say that this set of routines is very low level, but C++ itself is low level, too...

Important note: if the NTX exists but FFNtxOpen fails then wait a second and retry (this could happen if the NTX is locked by some other user).

Specification

Please refer to the Clipper NTX file specification.

Parameters
  • FFNtxOpen (the NTX can be opened regardless the opening of the related DBF file):
    • pointer to the NTX path
    • pointer to the NTX filename
  • FFNtxGetCount:
    • pointer to the ASCII key to search (don't worry about the trailing zero, the string should exactly be as long as the key length returned by the FFNtxOpen function call)
  • FFNtxGetFirst:
    • (no parameters)
  • FFNtxGetNext:
    • (no parameters)
  • FFNtxClose:
    • (no parameters)

Return value

  • FFNtxOpen:
    • 0: open failed
    • >0: open successful, field key length is returned (excluded the trailing zero)
  • FFNtxGetCount:
    • -1: an error occurred
    • 0: no matching records
    • >0: number of matching records
  • FFNtxGetFirst:
    • record number of the first matching record
  • FFNtxGetNext:
    • record number of the next matching record, or zero if the list is finished
  • FFNtxClose:
    • (no return value)

Application example

See also

Notes

The NTX topic is also covered in another section of my web pages for the programmer, one of the first section that I published in 2000.