Board index » delphi » Unexpected listbox behaviour

Unexpected listbox behaviour

Ok I am totally stumped here with a listbox problem:

I have an app with an array of 2000 strings.

When I use this code for a MEMO:

       count := 0;
        while fileslist[count] <> '' do
        begin
            Memo2.Lines.Add(fileslist[count]);
            Inc(count);
        end;

The MEMO perfectly shows all the strings from the array.

But when I use this code for a LISTBOX:

        count := 0;
        while fileslist[count] <> '' do
        begin
            ListBox.Items.Add(fileslist[count]);
            Inc(count);
        end;

I get 2 strange results:

1. There are double entries for some of the strings (it seems random
which ones get doubled).

2. Only about 500 or so of the strings are added to the listbox.

I have tried using Append instead of Add but get the same results.

Anybody know what the heck the problem is with my listbox ?

 

Re:Unexpected listbox behaviour


Quote
Dave wrote in message ...
>Ok I am totally stumped here with a listbox problem:

>I have an app with an array of 2000 strings.

>When I use this code for a MEMO:

>       count := 0;
>        while fileslist[count] <> '' do
>        begin
>            Memo2.Lines.Add(fileslist[count]);
>            Inc(count);
>        end;

>The MEMO perfectly shows all the strings from the array.

>But when I use this code for a LISTBOX:

>        count := 0;
>        while fileslist[count] <> '' do
>        begin
>            ListBox.Items.Add(fileslist[count]);
>            Inc(count);
>        end;

>I get 2 strange results:

>1. There are double entries for some of the strings (it seems random
>which ones get doubled).

>2. Only about 500 or so of the strings are added to the listbox.

>I have tried using Append instead of Add but get the same results.

>Anybody know what the heck the problem is with my listbox ?

Not me. The code look identical, apart from the Memo.Lines/ListBox.Items.

What happens when you wrap the loop in Begin/EndUpdate? That would be
on the Lines/Items, I think.

Have you tried keeping that array of strings in a TStrings? As a bonus,
you could then assign the whole list at once to Lines/Items.

Groetjes,
Maarten Wiltink

Re:Unexpected listbox behaviour


Quote
Dave <dtisd...@iname.com> wrote in message

news:ll67cts4lm4kl7qa0smfgarskid9s9bkrt@4ax.com...

Quote
> Ok I am totally stumped here with a listbox problem:

> Anybody know what the heck the problem is with my listbox ?

Hi,
I have tried to reproduce your problem, but I in my case everything works as
expected.
I think you need to post the code that fills the array.

Other Threads