How to compare 2 items of an listbox and 2 lines of a Memo? How do I give an item of an Listbox a variabele? How do I give a line of a Memo a variabele?
-
Have you tried anything? Please edit your question and include the code that you've tried to write. Then ask a question specific to the code example. You question suggests you might benefit from one of many tutorials available from Embarcadero, including http://www.embarcadero.com/firemonkey/firemonkey-e-learning-series – James L. Oct 26 '13 at 06:28
1 Answers
ListBox items
The contents of a ListBox is stored in TListBox.Items
which is of type TStrings
. This is a zero-based list/array of strings, thus in order to get the second item in the ListBox call one of the following:
ListBox1.Items.Strings[1]
, orListBox1.Items[1]
, becauseStrings[]
is the default property.
Memo lines
The contents of a Memo is stored in TMemo.Lines
which also is of type TStrings
, thus to get the first line of the Memo, call:
Memo1.Lines.Strings[0]
, orMemo1.Lines[0]
.
Comparison/relational operators
=
equality<>
inequality<
smaller- etc...
All together
Thus to compare the first line of the Memo with the second item of the ListBox, do:
if Memo1.Lines[0] <operator> ListBox1.Items[1] then
For example: when you want to check whether both are equal:
if Memo1.Lines[0] = ListBox1.Items[1] then
Going advanced
Maybe a simple comparison operator does not give enough information about the difference between the two strings. Then use a function instead of an operator to compare the two strings, see the units SysUtils
and StrUtils
. For example, when you want to compare both strings for having the same text, regardless case:
if SameText(Memo1.Lines[0], ListBox1.Items[1]) then
Comparing 4 items simultaneously
Concatenate two comparisons with a boolean/logic operator:
if (Memo1.Lines[0] = ListBox1.Items[0]) and (Memo1.Lines[1] = ListBox1.Items[1]) then

- 43,011
- 8
- 105
- 200