使用 Delphi 通过 COM 读取 Outlook 约会... 代码运行良好,但定期约会除外。我读到的所有内容都说我需要使用 RecurrencePattern 和 GetOccurrence 并确定下一个约会应该在哪里,然后尝试获取它,看看它是否失败......这似乎是一种非常“笨拙”的方式。
有没有人已经写过这样的东西?显然,experts-exchange 上有一些代码,但我在那里没有订阅......找不到其他任何东西。
理想情况下(我会尽我所能),我想要一个例程,说..这个约会有 6 次出现,这里是每次出现的所有 TDateTimes 的数组。
请注意,所有这些代码都可以正常工作。我只需要帮助填写代码的底部部分来构建重复模式。
代码片段---并非所有代码都显示---...根据要求...
访问 Outlook...
try
Outlook := GetActiveOleObject('outlook.application');
Form1.SB1.SimpleText := 'Outlook already started';
except
try
Outlook := CreateOleObject('outlook.application');
Created := True;
Form1.SB1.SimpleText := 'Outlook not running. Starting Outlook API';
except
// Unable to access or start OUTLOOK
MessageDlg(
'Unable to start or access Outlook. Possibilities include: permission problems, server down, or VPN not enabled. Exiting...', mtError, [mbOK], 0);
exit;
end;
end;
...获取我的收件人的日历...
// Now get the calendar entry
Calendar := Namespace.GetSharedDefaultFolder(Recip, 9);
现在将过滤器设置为将约会限制在日期范围内,并包括重复。
// If here, everything is good so far...
// user name, email, and Calendar is accessible
MyItems := Calendar.Items;
MyItems.Sort('[Start]', False);
MyItems.IncludeRecurrences := True;
// Set the filter dates... SECONDS can NOT be shown...
FilterStartDate := FormatDateTime('mmmm dd, yyyy', StartDate);
FilterStartDate := FilterStartDate + ' 12:00 AM';
FilterEndDate := FormatDateTime('mmmm dd, yyyy', EndDate);
FilterEndDate := FilterEndDate + ' 11:59 PM';
RestrictDateFilter := ('[Start]>' + CHR(34) + FilterStartDate + CHR(34) + 'and ' + '[Start]<' + CHR(34)
+ FilterEndDate + CHR(34));
DebugIt('RestrictFilter:', RestrictDateFilter);
Application.ProcessMessages;
ItemCollection := MyItems.Restrict(RestrictDateFilter);
ItemCollection.Sort('[Start]', False);
阅读我的第一次约会
// Try to read the first appoint, or error message if no appointments
try
Appointment := ItemCollection.GetFirst;
except
DebugIt('No appointments found', '');
MessageDlg('Unable to retrieve any appointments in this time frame.', mtError, [mbOK], 0);
exit;
end;
在遍历所有约会时...
if Appointment.IsRecurring = True then
begin
// Recurring Appointment, in a Valid RANGE
DebugIt('Repeating appointment starting on ' + DateToStr(Appointment.Start), '');
// If yearly repeating, we want to ignore
RP := Appointment.GetRecurrencePattern;
DebugIt('Determining appointment recurrence pattern', '');
if ((RP.RecurrenceType = olRecursYearly) or (RP.RecurrenceType = olRecursYearNth)) then
begin
// ignore these appointments
end
else
begin
// HERE IS WHERE I NEED HELP
// How do I determine all of the appointments based on the recurrences?
end;
end;
谢谢 GS