Re:ListBox question!
Quote
> Now I have another problem, how do I delete one 'A' from a list of many
> 'a's but only one and it doesn't matter which? Thanks in Advance.
Well, if it doesn't matter which use this:
index:=listbox1.items.indexof('a');
if index>=0 then listbox1.items.delete(index);
if you want to drop a random one, then you need to cycle through, build a list
of the items that are 'a' and then drop a random one...
(untested code)
var
items : array of integer;
i : integer;
begin
for i:=0 to listbox1.items.count-1 do // cycle through
if listbox.items[i]='a' then begin // found
setlength(items,length(items)+1); // inefficient but quick to code
items[high(items)]:=i; // save this item
end;
if length(items)>0 then begin
listbox1.items.delete(items[random(length(items))]);
// select random entry from the items array,
// and delete the item it points to
end;
end;
johannes
--
Please reply in this newsgroup only
- SIP solutions -
http://www.sipsolutions.de/