Board index » delphi » Listbox Question

Listbox Question

Hi
I have a Listbox with filenames of a dierectory in it.
How do I extract all filenames begining with the letter
S  to another listbox.
Thanks in Advance
Tez

 

Re:Listbox Question


Quote
>How do I extract all filenames begining with the letter
>S  to another listbox.

This is from memory only, so if it has some bug, you have to excuse me :)

You could do this:

for x:=0 to MyList.items.count-1 do begin
    if AnsiUpperCase(copy(MyList.items[x],0,1))='S' then
MyOtherList.Items.add(MyList.items[x]);
end;

-Geir-

Re:Listbox Question


Quote
>I have a Listbox with filenames of a dierectory in it.
>How do I extract all filenames begining with the letter
>S  to another listbox.

Just use the items property to walk through the list. To optimize the speed
use the Tlistbox.items.beginupdate and
Tlistbox.items.endupdate methods to prevent the other listbox from updating

Arjan

Re:Listbox Question


Quote
In article <01bd7584$e4a826c0$c30b26cb@166pentium>, "Terry Bennett" <byte...@space.net.au> wrote:

>Hi
>I have a Listbox with filenames of a dierectory in it.
>How do I extract all filenames begining with the letter
>S  to another listbox.
>Thanks in Advance
>Tez

try this, it will copy all files beginning with 'S' from
listbox1 to listbox2....

procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
begin
for i := 0 to listbox1.items.count -1 do
      begin
      if pos('S',listbox1.items[i]) = 1 then
           listbox2.items.add(listbox1.items[i]);
      end;
end;

Good luck

Brian Aitken aitk...@wbinet.com

Re:Listbox Question


In article <01bd7584$e4a826c0$c30b26cb@166pentium>,
   "Terry Bennett" <byte...@space.net.au> wrote:

Quote
>Hi
>I have a Listbox with filenames of a dierectory in it.
>How do I extract all filenames begining with the letter
>S  to another listbox.
>Thanks in Advance
>Tez

var
  i: Integer;
  FileName: String;

begin;
  for i := 1 to FileList.Items.Count - 1 do
  begin
    //Make the check not case sensitive
    FileName := Lower(FileList.Items[i]);
    if FileName[1] = 's' then
      AllSFileList.Add(FileList.Items[i];
  end;
end;

Hope there are no errors in this, my books on delphi are at home, written from
memory only!

Trevor Hand

Other Threads