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

last entry in a TStringList

0 views
Skip to first unread message

vm

unread,
Aug 2, 2001, 1:14:48 AM8/2/01
to
How do i safely check to see
if the last entry in a TStringList
is empty?
Thanks!
--
ôżô
V e r n www.parentpresent.org


Jonas Malmsten

unread,
Aug 2, 2001, 1:19:44 AM8/2/01
to

function LastIsEmpty(sl: TStringList): Boolean;
begin
Result := (sl.Count > 0) and (sl[sl.Count - 1] = '');
end;

"vm" <v...@gte.net> wrote in message news:3b68e052_1@dnews...

vm

unread,
Aug 2, 2001, 1:57:27 AM8/2/01
to
With
IF LastIsEmpty(ButtonLines) Then BREAK;

Still get class EStringListError with message 'List index out of bounds
(71)'.

--
ô¿ô

"Jonas Malmsten" <ne...@malmsten.net> wrote in message
news:3b68e1fc_1@dnews...


>
> function LastIsEmpty(sl: TStringList): Boolean;
> begin
> Result := (sl.Count > 0) and (sl[sl.Count - 1] = '');
> end;
>
> "vm" <v...@gte.net> wrote in message news:3b68e052_1@dnews...
> > How do i safely check to see
> > if the last entry in a TStringList
> > is empty?
> > Thanks!
> > --

> > ô¿ô

Jonas Malmsten

unread,
Aug 2, 2001, 2:09:14 AM8/2/01
to
hmm...

either 1) you have switched on complete evaluation in your compiller options
(default is off) or 2) your exception is generated by something else or 3)
I'm having one of those days when I should not write one single line of
code. Also make sure that the tstringlist has been created properly, however
that should not generate the type of error you are receiving.... Post some
more code describing what you are doin'.

/Jonas

"vm" <v...@gte.net> wrote in message news:3b68ea50$1_1@dnews...

Nick Hodges (TeamB)

unread,
Aug 2, 2001, 2:25:11 AM8/2/01
to
On Wed, 1 Aug 2001 19:14:48 -1000, "vm" <v...@gte.net> wrote:

>How do i safely check to see
>if the last entry in a TStringList
>is empty?

Before answering that, can you tell me why you want to know this
information? I see from the other answer that you are getting a List
Index out of bounds error. Is that the real problem here? If so, fix
that problem, and don't try to figure out what the last line in your
stringlist is doing.


Nick Hodges - TeamB
HardThink, Inc.

vm

unread,
Aug 2, 2001, 3:03:32 AM8/2/01
to
1) yes, {$B-}

2) // roughly i am doing this:

InLinesCurLinesCnt := 0;
ButtonLines := TStringlist.Create;
ButtonLines.LoadFromFile(OpenedFileName);
............
WHILE InLinesCurLinesCnt <= ButtonLines.count DO
..........
WHILE InLinesCurLinesCnt <= ButtonLines.count DO
// Parse each line from file.

BEGIN
......................
IF InLinesCurLinesCnt = ButtonLines.count THEN // BREAK;
Begin
IF LastIsEmpty(ButtonLines) Then BREAK;
End;
INC(InLinesCurLinesCnt);
.....................
3)

Function TForm1.LastIsEmpty(sl: TStringList): Boolean;


begin
Result := (sl.Count > 0) and (sl[sl.Count - 1] = '');
end;


--
ôżô

Paul Nicholls

unread,
Aug 2, 2001, 3:12:13 AM8/2/01
to
>WHILE InLinesCurLinesCnt <= ButtonLines.count DO

Ouch! you should be using < instead of <= as the index goes from 0 to
Count - 1

What you have there will definitely cause the out of bounds exception you
were describing...

--
Paul Nicholls (Delphi 5) Live long and optimise!
"Life is a beach - every so often you are swept out to sea by a rip and get
into trouble!" - Paul Nicholls

Home Page: www.southcom.com.au/~phantom
< IF YOU WANT TO EARN MONEY WHILE YOU SURF ON THE NET GO HERE: >
< http://www.alladvantage.com/go.asp?refid=BEM-274 >


Ralph Friedman (TeamB)

unread,
Aug 2, 2001, 7:14:38 AM8/2/01
to
Vm,

in article <3b68e052_1@dnews>, you wrote:

> How do i safely check to see
> if the last entry in a TStringList
> is empty?
>

if myStringList.Count > 0 then
if myStringList[Pred(myStringList.Count] = '' then


---
Regards
Ralph (TeamB)
***

Mike Orriss (TeamB)

unread,
Aug 2, 2001, 7:32:54 AM8/2/01
to
In article <3b68f9ce_2@dnews>, Vm wrote:
> WHILE InLinesCurLinesCnt <= ButtonLines.count DO
>

This should be:

WHILE InLinesCurLinesCnt < ButtonLines.count DO


Mike Orriss (TeamB and DevExpress)


Rudy Velthuis (TeamB)

unread,
Aug 2, 2001, 7:41:20 AM8/2/01
to
In article <3b68e052_1@dnews>, vm says...

> How do i safely check to see
> if the last entry in a TStringList
> is empty?

if YourList[YourList.Count - 1] = '' then

--
Rudy Velthuis (TeamB)

vm

unread,
Aug 2, 2001, 1:25:55 PM8/2/01
to
<Ouch! you should be using < instead of <= as the index goes from 0 to
Count - 1>
Ugh!
Thanks!
--
ô¿ô"Paul Nicholls" <paul_f_...@hotmail.com> wrote in message
news:3b68fceb_1@dnews...

vm

unread,
Aug 2, 2001, 1:27:08 PM8/2/01
to
Ugh!
Mahalo!

--
ôżô
V e r n www.parentpresent.org
"Mike Orriss (TeamB)" <m...@3kcc.co.uk> wrote in message
news:VA.0000242c.3b2db875@mikemain...
0 new messages