看看下面这段程序也许有帮助的。
procedure TfrmMessageEditor.btnAttachmentClick(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
TIdAttachment.Create(IdMsgSend.MessageParts, OpenDialog1.FileName);
ResetAttachmentListView;
end;
end;
procedure TfrmMessageEditor.ResetAttachmentListView;
var li: TListItem;
idx: Integer;
begin
lvFiles.Items.Clear;
for idx := 0 to Pred(IdMsgSend.MessageParts.Count) do
begin
li := lvFiles.Items.Add;
if IdMsgSend.MessageParts.Items[idx] is TIdAttachment then
begin
li.ImageIndex := 0;
li.Caption := TIdAttachment(IdMsgSend.MessageParts.Items[idx]).Filename;
li.SubItems.Add(TIdAttachment(IdMsgSend.MessageParts.Items[idx]).ContentType);
end
else
begin
li.ImageIndex := 1;
li.Caption := IdMsgSend.MessageParts.Items[idx].ContentType;
end;
end;
end;