The QMReadBlk() function reads a specified number of bytes from a sequential file. It is analogous to the QMBasic READBLK statement.
The function arguments are:
|FileNo||is the file number returned by a previous QMOpenSeq() call.|
|Bytes||is the number of bytes to be read.|
|ActualBytes||is an integer variable to receive the actual byte count which may be less than Bytes if the end of the data is reached. Note that this argument is not present in all variants of the QMClient API.|
The QMReadBlk() function requests the server to return the given number of bytes from the file opened as FileNo.
If successful, the function returns the data and the ActualBytes variable is set to the number of bytes read.
If the data cannot be read, typically because the end of the file has been reached, the function returns a null string and the ActualBytes variable is set to zero. The QMStatus() function can be used to retrieve the error number.
Note that when using the QMClient API in its wide character (Unicode) mode, QMReadBlk is a byte level operation and returns a string in which each character will represent one byte from the file and hence is always in the range char(0) to char(255).
The example program fragments below open a sequential item named STOCK in the IMPORT file, read100 bytes of data and then closes the file. A real program should test the error status from the read to determine if the action was successful.
char * QMReadBlk(int FileNo, int Bytes, int * ActualBytes)
fData = QMOpenSeq("IMPORT", "STOCK", 0);
Rec = QMReadBlk(fData, 100, &Err);
The returned pointer references a dynamically allocated memory area that must be released using QMFree() when no longer needed. Note that attempting to read beyond the end of the file returns a pointer to a null string, not a NULL pointer.
QMReadBlk(ByVal FileNo as Integer, ByVal Bytes as Integer, ByRef ActualBytes) as String
fData = QMOpenSeq("IMPORT", "STOCK", 0)
Rec = QMReadBlk(fData, 100, Err)
fData = session->OpenSeq("IMPORT", "STOCK", 0)
Rec = session->ReadBlk(fData, 100)
String ReadBlk(int FileNo, int Bytes)
fData = qm.OpenSeq("IMPORT", "STOCK", 0);
Rec = qm.ReadBlk(fData, 100);
If successful, the ServerError property will be set to SV$OK. Other values indicate an error.
fData = qm.OpenSeq("IMPORT", "STOCK", 0)
Rec, Err = qm.ReadBlk(fData, 100)
QMOpenSeq(), QMReadSeq(), QMSeek(), QMWeofSeq(), QMWriteBlk(), QMWriteSeq()