Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Associating Strings from two lists

0 views
Skip to first unread message

Alan Hale

unread,
Nov 3, 1998, 3:00:00 AM11/3/98
to
I want to be able to associate pairs of strings selected by a user
from separate list boxes. So the user will pick a string from the
first box and then "associate" with it a string selected from the
second box. I do not really want to concatenate the two strings
(because I would have to parse them out again later) but I do wnat to
be able to sort them together.

I have thought of using a TStringlist, perhaps treating the second
string as an object, but a) this doesnt feel right and b) I don't know
how to treat the string as an object!. Can anyone please suggest the
best way of implementing this? (Delphi 3 BTW).

Many thanks

Alan Hale

AlanGLLoyd

unread,
Nov 3, 1998, 3:00:00 AM11/3/98
to

In article <363f39e6...@news.clara.net>, adh...@clara.net (Alan Hale)
writes:

I think you have to be more explicit regarding the user interface. Do you want
to display a list showing the pairs of associated strings. When a string is
chosen does it need to be removed from the list so that it cannot be chosen
again. How many strings do you have. How many are displayed at a time, Which
string will it be sorted on. Is it sorted on the one string or on the
concatenated pair.


You could arrange to select items in both list boxes (by clicking). Have two
stringlists, one of which is sorted. Then when you click a button (only enabled
if a selection is made in both listboxes) the two strings are placed in
stringlists. Remove them fron the listboxes if that is what you want. Place the
one in the sorted list first and insert the other in the unsorted stringlist at
the position of the one in the sorted list (finding with IndexOf()).

SortStrList.Add(ListBox1.Items[ListBox1.ItemIndex]); // Add to sorted string
list
UnSortStrList.Insert(SortStrList.IndexOf(ListBox1.Items[ListBox1.ItemIndex],
ListBox2.Items[ListBox2.ItemIndex]).//add to
unsorted to pair it
{delete selected item from listbox1}
ListBox1.Items.Delete(ListBox1.ItemIndex);
ListBox1.ItemIndex := -1; // clear any selection
{delete selected item from listbox2}
ListBox2.Items.Delete(ListBox2.ItemIndex);
ListBox2.ItemIndex := -1; // clear any selection

Thus you have two stringlists with the associated pairs having the same
stringlist indexes..

There are two or three other solutions which depend on the answers to my
original questions.

ie this is a "multi-option felicide" situation (many ways of killing a cat)
<gg>

Alan Lloyd
alang...@aol.com


Alex

unread,
Nov 3, 1998, 3:00:00 AM11/3/98
to
Hi,

I'm not sure what your problem is,but maybe I have encountered a similar
problem. Could you be more specific? Give a few examples?

Regards, Alex


Alan Hale wrote:

> I want to be able to associate pairs of strings selected by a user
> from separate list boxes. So the user will pick a string from the
> first box and then "associate" with it a string selected from the
> second box. I do not really want to concatenate the two strings
> (because I would have to parse them out again later) but I do wnat to
> be able to sort them together.
>
> I have thought of using a TStringlist, perhaps treating the second
> string as an object, but a) this doesnt feel right and b) I don't know
> how to treat the string as an object!. Can anyone please suggest the
> best way of implementing this? (Delphi 3 BTW).
>

> Many thanks
>
> Alan Hale

--

*Being paranoid doesn't mean nobody is following you...:-)*

'When you have eliminated all which is impossible, then whatever remains,
however improbable, must be the truth..'- Sherlock Holmes

Alan Hale

unread,
Nov 4, 1998, 3:00:00 AM11/4/98
to
OK, to be specific, I will have two listboxes containg two lists. I
want the user to pick a string from list1, then a string from list2
and create a link between these two. The user will then select another
string from List1 and from list2 and link these together.

I need tosort the associated pairs of strings on the first string in
each pair.

Now, in fact I also need to parse out substrings of the second string,
to give two substrings.

What I am working onnow is to create an object to hold the two
substrings of the second string, and save that in a TStringList (using
AddObject) along with the first string. I think this will do the job -
but any comments welcome!

Many Thanks

Alan Hale

Menno Avegaart

unread,
Nov 4, 1998, 3:00:00 AM11/4/98
to
Try using the object of stringlist 1 to store the index of the string in
stringlist 2 (You could use drag 'n drop to do this).

Store:
Listbox1.Items.Objects[Listbox1.ItemIndex] := Pointer(Listbox2.ItemIndex);

Retreive:
Listbox2.ItemIndex := Integer(Listbox1.Items.Objects[Listbox1.ItemIndex]);


0 new messages