【发布时间】:2021-01-15 21:58:02
【问题描述】:
我在 Delphi 10.3 (RIO) 中开发,使用 add-in-express ver 9.x 编写 Outlook 插件 我只想从附件列表中“选择”文件。
我将按钮添加到 adxRibbonContextMenu 对象, 当我用鼠标在附件列表中的一个(选定的)或多个文件上单击右键时, 我希望能够只获得选定的一个(一个或多个)。
我在 VB 或 C# 中提供了一些解决方案 - 如何聊天 AttachmentSelection 对象。 但我看不到如何将它翻译成 Delphi。
我试过类似的东西:
Var
AttachmentSelection: OleVariant;
ExploreeSelection: OleVariant;
ISelection: Selection;
i,j: integer;
IExpl: _Explorer;
VIntf: OleVariant;
Intf: Outlook2000._MailItem;
begin
AttachmentSelection := OleVariant(RibbonControl.Context);
ShowMessage(IntToStr(AttachmentSelection.Class));
if AttachmentSelection.Class = 169 then // olAttachmentSelection = 169
begin
for i := 1 to AttachmentSelection.Count do begin
ShowMessage(AttachmentSelection.Item(i).FileName);
end;
end
else
if AttachmentSelection.Class = 34 then
begin // olExplorer = 34
IExpl := OutlookApp.ActiveExplorer();
ISelection := nil;
if Assigned(IExpl) then
try
try
ISelection := IExpl.Selection;
except
// "The Explorer has been closed and cannot be used for further operations"
ISelection := nil;
end;
finally
IExpl := nil;
end;
if Assigned(ISelection) then
Try
for i := 1 to ISelection.Count do
begin
//ShowMessage(ISelection.item(i));
VIntf := ISelection.Item(i);
ShowMessage(IntToStr(VIntf.Class));
if ((VIntf.Class = olAttachment) or (VIntf.Class = olAttachments)) Then
begin
ShowMessage('olAttachment or olAttachments');
end
else
if (VIntf.Class = olMail) Then
begin
ShowMessage('olMail');
IDispatch(Intf) := Self.OutlookApp.ActiveExplorer.Selection.Item(i);
for j := 1 to Intf.Attachments.count do
begin // this is not the selected list. it just "ALL THE LIST"
end;
end;
VIntf := Unassigned;
end;
finally
ISelection := nil;
end;
end
else
begin
//ShowMessage('Not an AttachmentSelection');
end;
end;
但这给了我所有列表,我在附件项中找不到任何“选定”属性。 我查看了 IMIBO(扩展 mapi),也没有找到任何解决方案。
有人能拿到这份清单吗?
在 C# 中,代码是:来自https://www.add-in-express.com/forum/read.php?FID=5&TID=13763
object context = control.Context;
if (context is Outlook._Explorer)
{
MessageBox.Show("EXPLORER");
Outlook._Explorer window = context as Outlook._Explorer;
MessageBox.Show("Count: " + window.AttachmentSelection.Count);
GetAttachmentsInfo(item, window.AttachmentSelection);
Marshal.ReleaseComObject(window.AttachmentSelection);
}
else if (context is Outlook._Inspector)
{
MessageBox.Show("INSPECTOR");
Outlook._Inspector window = context as Outlook._Inspector;
MessageBox.Show("Count: " + window.AttachmentSelection.Count);
GetAttachmentsInfo(item, window.AttachmentSelection);
Marshal.ReleaseComObject(window.AttachmentSelection);
}
else if (context is Outlook._AttachmentSelection)
{
MessageBox.Show("ATTACHMENTSELECTION");
Outlook._AttachmentSelection attSelection = context as Outlook._AttachmentSelection;
MessageBox.Show("Count: " + attSelection.Count);
GetAttachmentsInfo(item, attSelection);
Marshal.ReleaseComObject(attSelection);
}
谢谢。
【问题讨论】:
-
请编辑您的问题并添加您翻译到 Delphi 的 C# 代码。
-
嗨 fpiette,谢谢。我编辑了我的 Q,我认为问题是我找不到与 Outlook._AttachmentSelection 等效的东西
标签: delphi outlook email-attachments