Stringlist - Delphi
This is a discussion on Stringlist - Delphi ; I have a problem with deleting an item from a stringlist
I have a main form with a series of edit boxes which when double clicked
launch a modal form with a listbox which loads a list of names from ...
-
Stringlist
I have a problem with deleting an item from a stringlist
I have a main form with a series of edit boxes which when double clicked
launch a modal form with a listbox which loads a list of names from a
stringlist which when clicked put the chosen name in the first edit box -
repeat for 1 to 5.
This works perfectly but I wanted to delete the picked name from the
stringlist to eliminate any possibility of it being picked twice.
I thought that this worked good but have realised that it only works if the
user clicks the first item in the listbox ie the stringlist never gets the
number of the itemindex from the list box which do change depending upon the
name clicked
code I'm using is as follows
var
i: integer;
begin
i := 0; // if this is not inialised I get an out of bounds error
Labour.ProjectList[i] := lbProjects.Items.Strings[lbProjects.ItemIndex];
//Stringlist on Main form allocated index
Labour.ProjectList.Delete(i);
end;
This compiles and runs OK but as I said the ProjectList[i] is never changed
from 0.
Whilst I can live with this I would appreciate any help in solving it
Thanks Kerry
-
Re: Stringlist
"Kerry Cain" <cooper@members.bordernet.com.au> wrote
> var i: integer;
> begin
> i := 0; // if this is not inialised I get an out of bounds error
> Labour.ProjectList[i] := lbProjects.Items.Strings[lbProjects.ItemIndex];
> //Stringlist on Main form allocated index
> Labour.ProjectList.Delete(i);
> end;
>
> This compiles and runs OK but as I said the ProjectList[i]
> is never changed from 0.
Kerry, In your code, I do not see where you are deleteing the
item from the project list, so why should the project list be
changed? Rgds, JohnH
-
Re: Stringlist
"Kerry Cain" <cooper@members.bordernet.com.au> wrote in message
news:482980e9@newsgroups.borland.com...
>
> This works perfectly but I wanted to delete the picked name from the
> stringlist to eliminate any possibility of it being picked twice.
>
> I thought that this worked good but have realised that it only works if
> the user clicks the first item in the listbox ie the stringlist never gets
> the number of the itemindex from the list box which do change depending
> upon the name clicked
>
> var
> i: integer;
> begin
> i := 0; // if this is not inialised I get an out of bounds error
An aside, the above is correct - local variables are not initialized, so yes
you must always initialize them.
> Labour.ProjectList[i] :=
> lbProjects.Items.Strings[lbProjects.ItemIndex]; //Stringlist on Main form
> allocated index
> Labour.ProjectList.Delete(i);
This code makes no sense, you are assigning a string to an existing item of
ProjectList, and then in the next line you delete that line.
Assuming Labour.ProjectList is the stringlist you wish to delete from, and
assuming the items there are in the same order as the listbox (presumably
you loaded the listbox from Labour.ProjectList) then the *only* line you
need is:
Labour.ProjectList.Delete(lbProjects.ItemIndex);
--
Wayne Niddery - TeamB (www.teamb.com)
Winwright, Inc. (www.winwright.ca)
-
Re: Stringlist
Kerry Cain wrote:
> I have a main form with a series of edit boxes which when double
> clicked launch a modal form with a listbox which loads a list of
> names from a stringlist which when clicked put the chosen name in the
> first edit box - repeat for 1 to 5.
Ever heard of comboboxes <g>?
--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
-
Re: Stringlist
Peter Below (TeamB) wrote:
> Kerry Cain wrote:
>
>> I have a main form with a series of edit boxes which when double
>> clicked launch a modal form with a listbox which loads a list of
>> names from a stringlist which when clicked put the chosen name in the
>> first edit box - repeat for 1 to 5.
>
> Ever heard of comboboxes <g>?
>
yea my comment also - - -
Jim P.