R
R
Romanson2016-03-22 09:27:00
Delphi
Romanson, 2016-03-22 09:27:00

Damn, I can’t figure out why the program slows down during the cycle ...?

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;
  Application.ProcessMessages;
  Sleep(100);
  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);
    /// ----------------------
    for i := 0 to basa.Count - 1 do
    begin

      c := basa.Strings[i];
      if length(c) = 1 then
        v := c

      else
      begin

        v := copy(c, 1, 2);

        if v = s1 then
          ListBox2.Items.Add(basa.Strings[i]);

      end;
         Application.ProcessMessages;
  Sleep(100);
    end;

Application.ProcessMessages;
  Sleep(100);
- this is necessary for displaying aniindicator'a in the application and with the addition of pplication.ProcessMessages; slows down even worse than without it, because even without it, processing the database even in 60 lines already takes time. On the PC everything flies, on the phone it slows down.
Is there any other way to implement all of this? tell

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-03-22
@OLS

Try ListBox2.Items.BeginUpdate() before the loop and ListBox2.Items.EndUpdate() after it ends.
And remove sleep(100) - in your case they are not needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question