|
The QMReplace() function replaces the content of a field, value or subvalue in a dynamic array. It is analogous to the QMBasic REPLACE() function.
The function arguments are:
| Src | is the dynamic array to be processed |
| Fno | is the number of the field to be replaced. If zero, 1 is assumed. If negative, a new field is appended to the dynamic array. |
| Vno | is the number of the value to be replaced. If zero, the entire field is inserted. If negative, a new value is appended to the specified field. |
| Svno | is the number of the subvalue to be replaced. If zero, the entire value is inserted. If negative, a new subvalue is appended to the specified value. |
| NewData | is the new data to form the new dynamic array element. |
The QMReplace() function returns a new dynamic array with the specified field, value or subvalue replaced.
This function is evaluated on the client system and does not require a server connection to be open.
The example program fragments below read a record with an update lock, use QMReplace() to modify it and then write it back to the file. A real program should test the error status from the read operations to determine if they were successful.
char * QMReplace(char * Src, int Fno, int Vno, int Svno, char * NewData)
Rec = QMReadu(fClients, ClientNo, TRUE, Err);
Rec2 = QMReplace(Rec, 1, Pos, 0, NewData);
QMWrite(fClients, ClientNo, Rec2);
QMFree(Rec);
QMFree(Rec2);
The returned pointer references a dynamically allocated memory area that must be released using QMFree() when no longer needed. Note that a statement of the form
rec = QMReplace(rec, 2, 0, 0, new_data)
will return a pointer to a newly allocated memory area, overwriting the rec pointer. The old memory is not freed by this call and it is therefore necessary to retain a pointer to the original rec string so that it can be freed later.
|
QMReplace(ByVal Src as String, ByVal Fno as Integer, ByVal Vno as Integer, ByVal Svno as Integer, ByVal NewData as String) as String
Rec = QMReadu(fClients, ClientNo, True, Err)
Rec = QMReplace(Rec, 1, Pos, 0, NewData)
QMWrite fClients, ClientNo, Rec
|
This function is not supported by the QMClient class module as it is a QMBasic function.
|
String Replace(String Src, int Fno, int Vno, int Svno, String NewData)
Rec = qm.Readu(fClients, ClientNo, true);
Rec = qm.Replace(Rec, 1, Pos, 0, NewData);
qm.Write(fClients, ClientNo, Rec2);
|
Replace(Src, Fno, Vno, Svno, NewData)
Rec, Err = qm.Readu(fClients, ClientNo, True)
Rec = qm.Replace(Rec, 1, Pos, 0, NewData)
qm.Write(fClients, ClientNo, Rec)
|
|