<< Click to Display Table of Contents >> Navigation: Apollo VCL Components > Installing and Using Apollo VCL > Searching for a key in an index that was created on two fields |
To do this, you would need to construct the Seek expression to be equal to the exact key value that was stored in the index file, except for any trailing spaces. However, if TApolloTable.SetExact is True, trailing spaces would also be required on the Seek value.
Say for example that your index expression was:
'UPPER(LAST+FIRST )'
where LAST and FIRST are both 20 characters wide. If you wanted to Seek for 'John Smith', your Seek value would have to be formatted like this:
'SMITH JOHN'
In this example, the last name value (Smith) not only had to be upper-cased, but would also have to be padded with spaces to the field width (20) before the first name value (John) could be appended to the end.
Here is a simple function that you can use in your application to pad search strings to the desired length.
function Pad( sVal, iLen ): String;
begin
// Truncate string if longer than specified length
if Length( sVal ) > iLen then
sVal := Copy( sVal, 1, iLen );
// Otherwise, pad string with spaces to desired length
while Length( sVal ) < iLen do
sVal := sVal + ' ';
// Return truncated or padded string value
Result := sVal;
end;
Delphi's UpperCase() function can be used to convert the search values to upper case before passing it on to TApolloTable's Seek method. Alternatively, you can force the user's input to upper case by simply setting the input mask on the TEdit control.
Below is a sample call to TApolloTable.Seek using the Pad() function above. This assumes that the user had input the FIRST name value in one TEdit box (Edit1) and the LAST name value in a second TEdit box (Edit2). The variable sSeekVal in this example was declared as a String type.
// Concatenate the two search values, padding as required
sSeekVal := Pad( Edit2.Text, 20 ) + Edit1.Text;
// Upper case search string, if not handled in TEdit masks
sSeekVal := UpperCase( sSeekVal );
// Issue the Seek call
if ApTbl.Seek( sSeekVal ) then
ShowMessage( 'Found!' )
else
ShowMessage( 'Not found!' );