Delphi XE5的新功能“ TListView内置搜索过滤”
在窗体的OnCreate事件中初始化TListView项。
procedure TForm1.FormCreate(Sender: TObject);
const
Books: array [0 .. 4] of string = (
'Delph abc',
'Delphi XE2入门',
' by DelphiXE',
'Delphi 2009 handbook');
var
Book: string;
begin
for Book in Books do
begin
ListView1.Items.Add.Text := Book;
end;
end;
在Button1的OnClick事件中执行搜索过滤。
procedure TForm1.Button1Click(Sender: TObject);
var
SearchResponder: ISearchResponder;
begin
SearchResponder := ListView1 as ISearchResponder;
SearchResponder.SetFilterPredicate(
function(Arg: string): Boolean
begin
Result := Arg.StartsWith('Delphi');
end);
end;