Editar

Partilhar via


FieldRef.SetFilter(Text [, Any,...]) Method

Version: Available or changed with runtime version 1.0.

Assigns a filter to a field that you specify.

Syntax

 FieldRef.SetFilter(String: Text [, Value: Any,...])

Parameters

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

String
 Type: Text
The filter expression. A valid expression consists of alphanumeric characters and one or more of the following operators: <, >, , &, |, and =. You can use replacement fields (%1, %2, and so on) to insert values at run time.

[Optional] Value
 Type: Any
Replacement values to insert in replacement fields in the filter expression. The data type of Value must match the type of FieldRef.

Remarks

If the method is called with a field for which a filter already exists, the filter is removed before a new one is set. You can construct filters using the following operators.

Operator Description
.. Range
& And
| Or
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
<> Different from
* Forms a part of value
@ Case-insensitive

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

Example

The following example opens the Customer table as a RecordRef variable that is named CustomerRecref. The Field Method (RecordRef) creates a FieldRef for the first field (No.) and stores the reference in the MyFieldRef variable. The GetFilter Method (FieldRef) retrieves the filters that are set on the No. field and stores the value in the Filter1 variable. The value of any filter that is set is displayed in a message box. The SetFilter method sets a filter that selects records from 10000 to 40000 in the No. field. The GetFilter Method (FieldRef) retrieves and stores the new filter in the Filter2 variable and displays it in a message. The value in the Filter1 variable is blank because no filter is set. The value in Filter2 is 10000..40000 because of the filter that is set by the SetFilter method.

var
    MyFieldRef: FieldRef;
    CustomerRecref: RecordRef;
    Filter1: Text;
    Filter3: Text;
    Text000: Label 'Filter before filters set: %1.';
    Text001: Label 'Filter after filters set: %1.';
begin
    CustomerRecref.Open(Database::Customer);  
    MyFieldRef := CustomerRecref.Field(1);  
    Filter1 := MyFieldRef.GetFilter;  
    Message(Text000, Filter1);  
    MyFieldRef.SetFilter('10000..40000');  
    Filter2 := MyFieldRef.GetFilter;  
    Message(Text001, Filter2);  
end;

FieldRef Data Type
Get Started with AL
Developing Extensions