Delphi and display list items

I use a list to display a simple list of file names. I also have an editing component that allows me to search for these elements with a simple one:

procedure TForm1.Edit1Change(Sender: TObject);
const
  indexStart = -1;
var
  search : array[0..256] of Char;
begin
  if edit1.Text='' then exit;
  StrPCopy(search, Edit1.Text) ;
  ListBox1.ItemIndex := ListBox1.Perform(LB_SELECTSTRING, indexStart, LongInt(@search));
end;

Now, is there a way to “selectively” display items in a list? I mean, if I look for an element that starts with "hello", then ONLY those that will greet, either obscure them or not see: = false at all will be displayed. Is there a way to accomplish this with a list?

thank!

Oh, this is Delphi 7 ...

+3
source share
2 answers

I always do this (and do this quite often):

array of string TStringList, . Edit1Change Items , .

,

var
  arr: array of string;

- ,

procedure TForm1.FormCreate(Sender: TObject);
begin
  SetLength(arr, 3);
  arr[0] := 'cat';
  arr[1] := 'dog';
  arr[2] := 'horse';
end;

procedure TForm1.Edit1Change(Sender: TObject);
var
  i: Integer;
begin
  ListBox1.Items.BeginUpdate;
  ListBox1.Items.Clear;
  if length(Edit1.Text) = 0 then
    for i := 0 to high(arr) do
      ListBox1.Items.Add(arr[i])
  else
    for i := 0 to high(arr) do
      if Pos(Edit1.Text, arr[i]) > 0 then
        ListBox1.Items.Add(arr[i]);
  ListBox1.Items.EndUpdate;
end;

, Edit1.Text; Edit1.Text.

Pos(Edit1.Text, arr[i]) > 0

Pos(Edit1.Text, arr[i]) = 1

TStringList

TStringList,

var
  arr: TStringList;

procedure TForm1.FormCreate(Sender: TObject);
begin
  arr := TStringList.Create;
  arr.Add('cat');
  arr.Add('dog');
  arr.Add('horse');
end;

procedure TForm1.Edit1Change(Sender: TObject);
var
  i: Integer;
begin
  ListBox1.Items.BeginUpdate;
  ListBox1.Items.Clear;
  if length(Edit1.Text) = 0 then
    ListBox1.Items.AddStrings(arr)
  else
    for i := 0 to arr.Count - 1 do
      if Pos(Edit1.Text, arr[i]) = 1 then
        ListBox1.Items.Add(arr[i]);
  ListBox1.Items.EndUpdate;
end;

, , , "bo" "Boston". ,

if Pos(AnsiLowerCase(Edit1.Text), AnsiLowerCase(arr[i])) > 0 then

if Pos(Edit1.Text, arr[i]) > 0 then
+7

, , Win32 API IAutoComplete TEdit, TListBox. TStrings IAutoComplete, , .

+1

Source: https://habr.com/ru/post/1754477/


All Articles