Clear Firemonkey TListView search text

感情迁移 提交于 2019-12-06 06:40:29
Dsm
for I := 0 to ListView1.Controls.Count-1 do
  if ListView1.Controls[I] is TSearchBox then
  begin
    TSearchBox(ListView1.Controls[I]).Text := '';
  end;

(based on DocWiki!)

Ricardo da Rocha Vitor

Thanks @Dsm, by answer. I will just suggest a trick to get TSearchBox just one time and store in a variable. Now it is not necessary to loop through the TListView.Controls every time. For example:

uses
 ..., FMX.SearchBox;

var
  SearchBox_ListView1: TSearchBox = nil;

...

if not Assigned(searchBox_listview1) then 
  for I := 0 to ListView1.Controls.Count-1 do
    if ListView1.Controls[I] is TSearchBox then
    begin
      SearchBox_listview1 := TSearchBox(ListView1.Controls[I]);
      Break;
    End;

... 

if Assigned(SearchBox_listview1) then
  SearchBox_listview1.Text := '';
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!