R
R
Romanson2016-03-22 10:19:14
Delphi
Romanson, 2016-03-22 10:19:14

What is another way to search for the first two characters of a string in a Memo loop?

in general, I am looking for the first two characters in each Memo line for subsequent comparison, it looks like this:
with the memo I pass everything to basa: TStringList;
Further

procedure TForm1.ListBox1ItemClick(const Sender: TCustomListBox;
  const Item: TListBoxItem);
var
  s1, s2, c, v, s, d: string;
  i: integer;
basa: TStringList; 
begin
  AniIndicator1.Enabled := true;
  AniIndicator1.Visible := true;
  basa := TStringList.Create;
  basa.Text := Memo1.Lines.Text; //- сюда передал базу
  ListBox2.Clear; //- сюда нужно выводить после поиска и сравнения
  s2 := ListBox1.Items[ListBox1.ItemIndex]; // выбрал строку
  if length(s2) = 1 then // проверил длину
    s1 := s2
  else

  begin
    s1 := copy(s2, 1, 2); // и тут начались танцы с бубном, первые 2 символа есть все нормально
  end;
  /// ----------------------
  for i := 0 to basa.Count - 1 do // этот цикл находит каждую строку при совпадении символов
  begin                                       // и выводит строку в listbox2, все работает с одним НО
    c := basa.Strings[i];       // работает на PC, а на Android тормозит, что делать с этим?
    if length(c) = 1 then
      v := c
    else
    begin
      v := copy(c, 1, 2);
      Application.ProcessMessages;
      sleep(10);
      if v = s1 then
      begin
                ListBox2.Items.Add(basa.Strings[i]);;
            Application.ProcessMessages;
      sleep(10);
      end;
    end;
  end;

for i := 0 to basa.Count - 1 do // this loop finds each string when characters match
begin // and outputs the string to listbox2, everything works with one BUT
c := basa.Strings[i]; // works on PC but slows down on Android, what to do about it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lofem, 2016-04-26
@Romanson

When making a lot of changes to visual components, most of the time is spent redrawing them. On a PC, this may not be very noticeable, but in mobile applications it is already felt.
To avoid this is quite simple, you need to write Listbox2.BeginUpdate() before making a change, and at the end of ListBox2.EndUpdate(). This will cause the component to change only once, after adding all the fields.
And I think it's better to remove sleep(10) or does it have some sacred meaning?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question