Seek

<< Click to Display Table of Contents >>

Navigation:  Apollo VCL Components > Apollo VCL Component Reference > TApolloTable > TApolloTable Methods >

Seek

Declaration

function Seek( sKeyValue: String ): WordBool;

Description

Searches the current order for a supplied key.

Parameters

sKeyValue: The value to search for. If the key is numeric, transform it to a string before passing it to Seek. Apollo will transform the string back to a number before performing the seek. Dates must be passed as strings in DTOS form (CCYYMMDD). Pass search keys to logical indexes as "T" or "F".

If elements of the key were created with the xBase DESCEND() function, use Descend to invert the key before passing it to Seek.

The search key value may be a partial key (if SetExact is not True).

Return Value

True if the key was found and False if not. If the return is False, Found will be False and, if EOFAction is set to eaEOF then EOF will be True. For failed Seeks, if EOFAction is set to eaMoveLast (the default) then EOF will be False and the record pointer will be positioned at the record referenced by the last key in the index.

The following conditions apply depending on the settings of SetExact and SetSoftSeek, and also assume that EOFAction is set to eaEOF:

A complete match in both value and length always returns True. Found will be True and Eof will be False.

A partial match will return True if SetExact is False. Found will be True and Eof will be False.

A partial match will return False if SetExact is True and SetSoftSeek is False (if SetSoftSeek is True, it overrides any SetExact setting).

If SetSoftSeek is False and the key is not found, False is returned.

If SetSoftSeek is True and a key is found that is greater than the requested key, Seek returns True, Found returns False, and Eof returns False.

If SetSoftSeek is True and EOF is encountered without finding any key, False is returned.

Delphi Example

// Found can be used when SoftSeek is True to determine whether the record found is a match or the result of finding a record after the requested key.

procedure Form1.Button1Click(Sender: TObject);

var

 cRecStr: String; 

begin

 // Get SEEK value from user

 sRecStr := SeekBox.Text; 

 if sRecStr = '' then  

         Exit; 

 sRecStr := UpperCase( sRecStr ); 

         ApolloEnv1.SetSoftSeek( True ); 

 if ApTbl.Seek( sRecStr ) then

 begin 

         if ApTbl.Found then 

                 ShowMessage( 'Exact or partial match!' ) 

         else 

                 ShowMessage( 'Soft seek - on record after' ); 

 end 

 else 

 begin 

         ShowMessage( 'Key Not Found' ); 

         ApolloEnv1.SetSoftSeek( False ); 

 end; 

 ApolloEnv1.SetSoftSeek( False ); 

end;

See Also

Descend, EOFAction, Found, SeekBin, SetExact, SetSoftSeek