RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TFilterComboBox.Filter Property

Contains all the file masks displayed in the filter combo box.

Pascal
property Filter: string;
C++
__property AnsiString Filter;

Set the Filter property to specify the names that appear in the filter combo box, along with the masks associated with each name. Each mask is a file name that may include wildcards. The asterisk (*) is a wildcard which matches any number of arbitrary characters. The question mark (?) is a wildcard which matches a single arbitrary character. When the application runs, the file filter the user selects in the filter combo box becomes the value of the Mask property.  

To create the value of Filter for a single file type, follow these steps: 

1Type some meaningful text to indicate the type of file. 

2Type a | character (vertical bar). 

3Type the file filter. 

Don't put in any spaces around the | character in the string. 

Here's an example:

FilterComboBox1.Filter := 'Text files|*.TXT';

 

FilterComboBox1->Filter = "Text files|*.TXT";

If Filter is set to this string, the string "Text files" appears in the filter combo box. When the user selects "Text files", the mask is set to "*.TXT". 

To specify multiple file filters, extend the value of Filter, separating each file name/mask combination with a | character. Filter can specify an any number of file filters, as long as the string is less than 255 characters.  

Here's an example of two file filters that could be specified as the value of the Filter property:

'Text files (*.TXT)|*.TXT|Pascal files (*.PAS)|*.PAS'

 

"Text files (*.TXT)|*.TXT|C++ files (*.CPP)|*.CPP"

The previous example includes the file filters in parentheses in the text parts. This isn't required, but it's a common convention that helps users understand what to expect when they select a file filter. 

The mask portion can include multiple file specifiers if they are separated with semicolons:

'All files|*.TXT;*.PAS;*.WB1'

 

"All files|*.TXT;*.CPP;*.RC"

 

C++ Examples: 

/*
This example uses a filter combo box and a file list box on
a form. When the user selects a filter in the filter combo
box, the file list box displays only files which match the
selected mask:
*/
void __fastcall TForm1::FilterComboBox1Change(TObject *Sender)
{
  FileListBox1->Mask = FilterComboBox1->Mask;
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  FilterComboBox1->Filter = "All files (*.*)|*.*| Executable files (*.exe)|*.exe";
}

 

Delphi Examples: 

{
This example uses a filter combo box and a file list box on
a form. When the user selects a filter in the filter combo
box, the file list box displays only files which match the
selected mask:
} 
procedure TForm1.FilterComboBox1Change(Sender: TObject);
begin
  FileListBox1.Mask := FilterComboBox1.Mask;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FilterComboBox1.Filter := 'All files (*.*)|*.*| Pascal files (*.pas)|*.pas';
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!