Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Feb : Viewing text/attachments in a newsreader using Indy 10 TIdNNTP component
| Subject: | Viewing text/attachments in a newsreader using Indy 10 TIdNNTP component |
| Posted by: | "John Mitson" (jrm..@hawaii.rr.com) |
| Date: | Mon, 19 Feb 2007 09:31:44 |
I am interested in being able to view nntp messages with or without
attachments. The procedure works fine for messages with attachments;
attachments for msgs without text are saved and text is displayed in
Memo1 for msgs containing text & attachments. However, messages without
attachments do not display text. I would have thought the "else"
portion of the procedure would provide me with an output for text only
messages. However, if I use the code commented out at the bottom I can
display text only messages. I am confused. Any thoughts of what I may
be doing wrong?
Any suggestions are greatly appreciated.
John
www.whitecaps-datasolutions.com
procedure TForm1.ObtainArticle(Sender: TObject);
var
partIdx: Integer;
li: TListItem;
begin
if ListView2.Selected <> nil then
begin
ListView3.Clear;
Memo1.Clear;
{We to typecast the Selected.Data which is the article index}
IdNNTP1.GetArticle(Integer(ListView2.Selected.Data), IdMessage1);
//for partIdx := 0 to Pred(IdMessage1.MessageParts.Count) do
for partIdx := 0 to IdMessage1.MessageParts.Count - 1 do
begin
if (IdMessage1.MessageParts.Items[partIdx] is TIdAttachmentFile)
then
begin //general attachment
li := ListView3.Items.Add;
li.ImageIndex := 8;
li.Caption :=
TIdAttachmentFile(IdMessage1.MessageParts.Items[partIdx]).Filename;
TIdAttachmentFile(IdMessage1.MessageParts.Items[partIdx]).SaveToFile(ExtractFilePath(GetModuleName(hInstance))
+ TIdAttachmentFile(IdMessage1.MessageParts.Items[partIdx]).Filename);
li.SubItems.Add(TIdAttachmentFile(IdMessage1.MessageParts.Items[partIdx]).ContentType);
end else
begin //body text
if IdMessage1.MessageParts.Items[partIdx] is TIdText then
begin
Memo1.Lines.Clear;
Memo1.Lines.AddStrings(TIdText(IdMessage1.MessageParts.Items[partIdx]).Body);
end;
end;
end;
end;
end;
{if IdMessage1.MessageParts.Count > 0 then
begin
for partIdx := 0 to IdMessage1.MessageParts.Count-1 do
begin
if IdMessage1.MessageParts[partIdx] is TIdText then
begin
Memo1.Lines.Text :=
TIdText(IdMessage1.MessageParts[partIdx]).Body.Text;
Exit;
end;
end;
end else
Memo1.Lines.Text := IdMessage1.Body.Text;
end;}