在我的(Delphi)代码中,我在Outlook中创建了一个新的日历约会:
function TDataModuleSyncOutlook.ExportEventToOutlook(AOutlookEvent: TcxSchedulerEvent; var AOutlookEntryID: String): Boolean;
var
AAppointmentItem: OleVariant;
begin
Result := false;
AAppointmentItem := FCalendarFolder.Items.Add(olAppointmentItem);
...
AAppointmentItem.Save; // This generates AAppointmentItem.EntryID
AOutlookEntryID := AAppointmentItem.EntryID;
...
我想维护一个指向FCalendarFolder.Items []中索引的EntryID列表。
运行代码我注意到新项目被添加到Items的前面,即它是FCalendarFolder.Items [1](Items是从1开始的。)
我的问题是:保证是这样吗?,即FCalendarFolder.Items.Add是否总是在FCalendarFolder.Items [1]中添加新约会? 因为如果不是,我如何将EntryID与索引相结合?'
如果无法保证,我该如何维护该交叉引用?我没有别的办法:
AppointmentItem object似乎没有.Index或.ItemIndex属性
通过EntryID查找项目,使用Items.Find或Items.Restrict明确不支持EntryID
背景:
使用GetDefaultFolder或GetSharedDefaultFolder检索FCalendarFolder为:
(基于Retrieve Outlook logged-in user SMTP address after connecting through OLE的代码)
const
olFolderCalendar = $00000009; // Outlook default calendar folder
olAppointmentItem = $00000001;
scxOutlookApp = 'outlook.application';
scxNameSpace = 'MAPI';
function TDataModuleSyncOutlook.ConnectToOutlook(AUserSMTP: String = ''): Boolean;
var
lNameSpace,
lRecipient,
lVar : OleVariant;
lLoginSMTP: String;
begin
Result := false;
FWasCreated := False;
try
FOutlookApp := GetActiveOleObject(scxOutlookApp); // Application object
Result := True;
except
try
FOutlookApp := CreateOleObject(scxOutlookApp);
FWasCreated := True;
Result := True;
except
on E:Exception do TSyncLogger.LogError(E.Message);
end;
end;
if Result then
begin
lNameSpace := FOutlookApp.GetNamespace(scxNameSpace);
lVar := FOutlookApp.Session; // NameSpace object for the current session
if not VarIsClear(lVar) then lVar := lVar.CurrentUser; // Recipient object for the currently logged-on user
if not VarIsClear(lVar) then lVar := lVar.AddressEntry; // AddressEntry object for the recipient
if not VarIsClear(lVar) then lVar := lVar.GetExchangeUser; // Returns an ExchangeUser object that represents the AddressEntry
if not VarIsClear(lVar) then lVar := lVar.PrimarySmtpAddress; // String representing the SMTP address for the ExchangeUser
if not VarIsClear(lVar) then
lLoginSMTP := FOutlookApp.Session.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress;
else
LogError(...)
if LowerCase(AUserSMTP) <> Lowercase(lLoginSMTP) then
begin // Open shared calendar if it's a different user
lRecipient := lNameSpace.CreateRecipient(AUserSMTP);
try
FCalendarFolder := lNameSpace.GetSharedDefaultFolder(lRecipient, olFolderCalendar);
except
on E:Exception do
begin
Result := false;
LogError(...);
end;
end;
end
else // ... otherwise open default calendar folder
begin
FCalendarFolder := lNameSpace.GetDefaultFolder(olFolderCalendar);
...
答案 0 :(得分:0)
绝对不是。除非您使用Items.Sort显式排序Items集合,否则根本没有订单。如果您知道条目ID,则可以使用Namespace.GetItemFromID重新打开该项目。