Board index » delphi » Stringlist {*word*218} question ?

Stringlist {*word*218} question ?

Hi All,

Just a quick one

How can I make this work :
------------
For
ReportItemCounter := 0 to SLienq [Items-1]

do ...

-----------

Where SLienq is a stringlist and ReportItemCounter  is an integer, I
only want the counter to go up the number of items in the striglist.

I can do it with listview items but I'm struggling with it.

Thanks,
Liam Healy

 

Re:Stringlist {*word*218} question ?


In article <hqLbMcBKWUr9E...@occpsy.demon.co.uk>, L. Healy
<L.He...@occpsy.demon.co.uk> writes

Quote
>Hi All,

>Just a quick one

>How can I make this work :
>------------
>For
>ReportItemCounter := 0 to SLienq [Items-1]

>do ...

>-----------

>Where SLienq is a stringlist and ReportItemCounter  is an integer, I
>only want the counter to go up the number of items in the striglist.

>I can do it with listview items but I'm struggling with it.

>Thanks,
>Liam Healy

Got it !

SLienq.Count-1

Liam Healy

Re:Stringlist {*word*218} question ?


On Wed, 16 Oct 2002 11:55:06 +0100, "L. Healy"

Quote
<L.He...@occpsy.demon.co.uk> wrote:
>Hi All,

>Just a quick one

>How can I make this work :
>------------
>For
>ReportItemCounter := 0 to SLienq [Items-1]

>do ...

>-----------

>Where SLienq is a stringlist and ReportItemCounter  is an integer, I
>only want the counter to go up the number of items in the striglist.

For  ReportItemCounter := 0 to SLienq.Count - 1 do...

--
jc

Re:Stringlist {*word*218} question ?


Maybe 'Count' is what you are after
Nice that it is zero based ... so intuitive.

procedure TForm1.Button1Click(Sender: TObject);
Var
  SL :TStringList;
  L9, Y :Integer;
begin
  SL := TStringList.Create;
  SL.Text := '1'#13#10'2'#13#10'3';
  Y := 0;
  For L9 := 0 To SL.Count - 1 Do
      Begin
        Canvas.TextOut( 0, Y, SL.Strings[L9]);
        Y := Y + 20;
      End;
end;

On Wed, 16 Oct 2002 11:55:06 +0100, "L. Healy"

Quote
<L.He...@occpsy.demon.co.uk> wrote:
>Hi All,

>Just a quick one

>How can I make this work :
>------------
>For
>ReportItemCounter := 0 to SLienq [Items-1]

>do ...

>-----------

>Where SLienq is a stringlist and ReportItemCounter  is an integer, I
>only want the counter to go up the number of items in the striglist.

>I can do it with listview items but I'm struggling with it.

>Thanks,
>Liam Healy

Re:Stringlist {*word*218} question ?


On Wed, 16 Oct 2002 12:05:03 GMT, Bounce_It_je...@iss.u-net.com_.bin
(J French) waffled on about something:

Quote

>Maybe 'Count' is what you are after
>Nice that it is zero based ... so intuitive.

>procedure TForm1.Button1Click(Sender: TObject);
>Var
>  SL :TStringList;
>  L9, Y :Integer;
>begin
>  SL := TStringList.Create;
>  SL.Text := '1'#13#10'2'#13#10'3';
>  Y := 0;
>  For L9 := 0 To SL.Count - 1 Do
>      Begin
>        Canvas.TextOut( 0, Y, SL.Strings[L9]);
>        Y := Y + 20;
>      End;
>end;

I'm glad both examples given used sl.count-1. A friend of mine insists
on using pred(sl.count), and it always makes me stumble as I try to
read his code!

/me wonders if another thread of "is x-1 faster slower than pred(x)"
is gonna start....

/me fondly remembers the "Is x:=x-1 faster than dec(x) that he
accidently started last year"...

Those were the days...

:o)

Dodgy.

Re:Stringlist {*word*218} question ?


In article <9ujqqucsrqll9ip4234rdtobr8itmk2...@4ax.com>, Jeremy Collins
<jd.coll...@ntlworld.com> writes

Quote
>On Wed, 16 Oct 2002 11:55:06 +0100, "L. Healy"
><L.He...@occpsy.demon.co.uk> wrote:

>>Hi All,

>>Just a quick one

>>How can I make this work :
>>------------
>>For
>>ReportItemCounter := 0 to SLienq [Items-1]

>>do ...

>>-----------

>>Where SLienq is a stringlist and ReportItemCounter  is an integer, I
>>only want the counter to go up the number of items in the striglist.

>For  ReportItemCounter := 0 to SLienq.Count - 1 do...

>--
>jc

Thanks, I think our posts crossed!
Liam Healy

Re:Stringlist {*word*218} question ?


On Wed, 16 Oct 2002 13:16:48 +0100, Dodgy

Quote
<Do...@earth.planet.universe> wrote:
>/me fondly remembers the "Is x:=x-1 faster than dec(x) that he
>accidently started last year"...

>Those were the days...

Where I come from INC  X  and  DEC  X
mean something rather different from Delphi

However even the most rudimentary compiler understands how to
translate :
    X := X + 1
into
   INC  EAX

Re:Stringlist {*word*218} question ?


On Wed, 16 Oct 2002 14:13:53 GMT, Bounce_It_je...@iss.u-net.com_.bin
(J French) waffled on about something:

Quote
>On Wed, 16 Oct 2002 13:16:48 +0100, Dodgy
><Do...@earth.planet.universe> wrote:

>>/me fondly remembers the "Is x:=x-1 faster than dec(x) that he
>>accidently started last year"...

>>Those were the days...

>Where I come from INC  X  and  DEC  X
>mean something rather different from Delphi

>However even the most rudimentary compiler understands how to
>translate :
>    X := X + 1
>into
>   INC  EAX

Where do you come from then?

/me is curious.

Dodgy.

Re:Stringlist {*word*218} question ?


On Wed, 16 Oct 2002 14:13:53 GMT, Bounce_It_je...@iss.u-net.com_.bin

Quote
(J French) wrote:
>On Wed, 16 Oct 2002 13:16:48 +0100, Dodgy
><Do...@earth.planet.universe> wrote:

>>/me fondly remembers the "Is x:=x-1 faster than dec(x) that he
>>accidently started last year"...

>>Those were the days...

>Where I come from INC  X  and  DEC  X
>mean something rather different from Delphi

>However even the most rudimentary compiler understands how to
>translate :
>    X := X + 1
>into
>   INC  EAX

In earlier versions of Delphi
  Inc(X)
was faster than
  X := X + 1
although that's no longer true...

--
jc

Re:Stringlist {*word*218} question ?


On Wed, 16 Oct 2002 16:04:34 +0100, Dodgy

Quote
<Do...@earth.planet.universe> wrote:

<snip>
Quote
>Where do you come from then?

>/me is curious.
Neanderthal

>Dodgy.

Re:Stringlist {*word*218} question ?


"Dodgy" <Do...@earth.planet.universe> schrieb im Newsbeitrag
news:arlqqusrccksbblm29qubpskbdsq6bi58e@4ax.com...

Quote
> I'm glad both examples given used sl.count-1. A friend of mine insists
> on using pred(sl.count), and it always makes me stumble as I try to
> read his code!

> /me wonders if another thread of "is x-1 faster slower than pred(x)"
> is gonna start....

How about a thread "Is 'for i := 0 to pred(sl.Count)' easier to read then
'for i := 0 to sl.Count - 1'"? I would vote for pred, of course.  ;-)

Uli.

Re:Stringlist {*word*218} question ?


In article <aomv08$oajq...@ID-99119.news.dfncis.de>, "Ulrich Gerhardt"

Quote
<ulrich.gerha...@gmx.de> writes:
>How about a thread "Is 'for i := 0 to pred(sl.Count)' easier to read then
>'for i := 0 to sl.Count - 1'"? I would vote for pred, of course.  ;-)

Depends on the context and whether one is getting the value less than another,
or a value before another. If its an index then Pred is more appropriate. If
its a number the -1 is more appropriate. It just happens that with ordinal
values a predicate takes the same value as one less than the value. But in my
opinion the fact that an ordinal value is allocated as a value for an item,
does not make the _item_ an ordinal item.

If the item is ordinal, then use Pred() & Succ(). If the item in not ordinal
(ie not inherently ordered and so not having a context of before and after)
then use -1 and +1.

Alan Lloyd
alangll...@aol.com

Other Threads