Muokkaa

Jaa


FieldRef.SetRange([Any] [, Any]) Method

Version: Available or changed with runtime version 1.0.

Sets a simple filter on a field, such as a single range or a single value.

Syntax

 FieldRef.SetRange([FromValue: Any] [, ToValue: Any])

Parameters

FieldRef
 Type: FieldRef
An instance of the FieldRef data type.

[Optional] FromValue
 Type: Any
The lower limit of the range. The data type of FromValue must match the data type of the field referred to by FieldRef.

[Optional] ToValue
 Type: Any
The upper limit of the range. If you omit this parameter, the FromValue you specified is used. The data type of ToValue must match the data type of the field referred to by FieldRef.

Remarks

The SetRange method provides a quick way to set a simple filter on a field. If you call this method by using a field that already has a filter, that filter is removed before the new filter is set.

If you omit all of the optional parameters, all filters set for that field are removed. The SetRange method fails if no field is selected.

This method is like the SetRange Method (Record) method.

Example

The following example opens the Customer table as a RecordRef object, creates a reference to the first (No.) field, and stores the reference in the MyFieldRef variable. The SetRange method sets a filter that selects all records from 10000 to 40000 in the No. field. The Find Method (RecordRef) searches and selects the first record in the filter and counts the number of records that are found. The number of records is stored in the Count variable. The process is repeated by looping through all the records in the filter until no more records are found. The number of records that are found in the range is stored in the Count variable and displayed in a message box.

var
    MyFieldRef: FieldRef;
    CustomerRecref: RecordRef;
    Count: Integer;
    Text000: Label '%1 records were retrieved.';
begin  
    CustomerRecref.Open(Database::Customer);  
    MyFieldRef := CustomerRecref.Field(1);  
    MyFieldRef.SetRange('10000' , '40000');  
    Count := 0;  
    if CustomerRecref.Find('-') then  
      repeat  
        Count := Count + 1;  
      until CustomerRecref.Next = 0;  
    Message(Text000 , Count);  
end;

FieldRef Data Type
Get Started with AL
Developing Extensions