- Unlike older versions of Pascal, Delphi's string type (without a length specifier) is dynamic and null terminated. This means that you are not guaranteed to have memory allocated to the string buffer until you assign it a value. This means when using the type string, you need to pad it large enough to hold the expected results. Using the StringOfChar() function, you can assign a blank string large enough to accommodate the expected return value from Btrieve, as illustrated in the following example:
CustKeyBuffer: string; //long string
CustBufLen : word;
//MAX_KEY_LEN is 255 since BTRV() always passes
//255 for the Key Length :
CustKeyBuffer := StringOfChar(` `,
MAX_KEY_LEN);
CustBufLen := SizeOf(CustRec);
Status := BTRV(B_GET_FIRST, CustPosBLock, CustRec,
CustBufLen, CustKeyBuffer, 0);
{CustKeyBuffer now has the value of the key
for}
{the record retrieved}
- Not all of the Delphi samples included in this chapter illustrate error reporting. However, you should check return codes after every call.
- If you try the samples in this chapter, for the Fetches that use the INTERNAL_FORMAT style, the order of the fields in the query must match the order of members you fetch from the data record. When you use the FillGridHeaders() routine, you must stuff the grid in the same order as the query lists the fields.