Re: EListError - List Index Out of Bounds [0]

Giganews Newsgroups
Subject: Re: EListError - List Index Out of Bounds [0]
Posted by:  Remy Lebeau \(Indy Team\) (no.spam@no.spam.com)
Date: Mon, 29 Jan 2007

"John Mitson" <jrm…@hawaii.rr.com> wrote in message
news:F6D9EE73D918E340jrm…@hawaii.rr.com...

> I encountered a run-time error on following line:
>
> Memo1.Lines.Text :=
TIdText(IdMessage1.MessageParts.Items[0]).Body.Text;

You are not checking the IdMessage1.MessageParts.Count property
beforehand, and you are not verifying that the first part is actually
a text part to begin with (it could be an attachment instead).  Not
all messages will have MessageParts items available.

Try this instead:

    procedure TForm1.Button1Click(Sender: TObject);
    var
        I: Integer;
    begin
        Memo1.Clear;
        IdNNTP1.GetArticle(74716, IdMessage1);
        if IdMessage1.MessageParts.Count > 0 then
        begin
            for I := 0 to IdMessage1.MessageParts.Count-1 do
            begin
                if IdMessage1.MessageParts[i] is TIdText then
                begin
                    Memo1.Lines.Text :=
TIdText(IdMessage1.MessageParts[I]).Body.Text;
                    Exit;
                end;
            end;
        end else
            Memo1.Lines.Text := IdMessage1.Body.Text;
    end;

Gambit

Replies

In response to

EListError - List Index Out of Bounds [0] posted by John Mitson on Sun, 28 Jan 2007