0

I have a TListBox that can have a very long stringlist when loaded so I have the operator initiate a Sort by clicking a button. Sometimes the sort can take close to a minute and the operator is left wondering what's happening.

Is there any way I can use a TProgressBar to show that something is happening? If so, how?

OR

Can I Grey (visually disabled) the screen at the start and then color back to white when the sort is completed? If so, how?

Thanks

  • 1
    Are you running the sort in a background thread? And how many items in the list? My bet is that you can get the sort done a couple of orders of magnitude faster. – David Heffernan Mar 09 '14 at 19:46
  • 1
    FWIW, for the sort to take a minute the list to have around 10 million items. If you have a lot fewer than this, then the solution to your problem is to fix the sort. – David Heffernan Mar 09 '14 at 20:03
  • @DavidHeffernan Thanks for the comments, there are abut 60,000 to maybe 90,000 long strings (300+ characters) that are to be sorted alphabetically. Idealy SQL would be better, but this is some old software I am trying to modify cheap for a small business, so a rewrite is out. I am just using the Listbox.Sort Method. Speed - dare I mention, it is running on win98! LOL –  Mar 09 '14 at 21:47
  • 1
    Are you using `TListBox.Items.BeginUpdate/EndUpdate`? That should speed things up. – LU RD Mar 09 '14 at 23:04
  • @LURD, that might be speed up things a bit, but was the `WM_SETREDRAW` message, which is behind `SetUpdateState` method of `TListBoxStrings` (at least in Delphi 2009) present on Windows 98 :-) ? – TLama Mar 09 '14 at 23:26
  • @TLama, never bothered to make a testplatform in VMware for W98. Have NT4 though. – LU RD Mar 09 '14 at 23:26
  • I wonder how can one answer if you can show a progress bar without knowing how are you sorting. The answer would be definitely no if you're setting Sorted on and off f.i. – Sertac Akyuz Mar 10 '14 at 00:59

1 Answers1

8

I believe that your fundamental problem is that you are using a visual control as a container. Sorting the list inside the container will have terrible performance. Put 60,000 strings in a TStringList and you'll be able to sort them instantly.

Rather than holding the items in the visual control, you can operate it in virtual mode. That will be the most efficient way to operate.

If you make these changes then you won't need a progress bar.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490