使用Delphi通过COM读取Outlook约会...
代码可以正常工作,但定期约会除外。
我读到的所有内容都说我需要使用RecurrencePattern和GetOccurrence并确定下一个约会应该在哪里,然后尝试获取它,看看它是否失败...这似乎是一种真正的“模糊”方式。
有没有人已经写过类似的东西?显然,关于experts-exchange有一些代码,但是我那里没有订阅……找不到其他东西。
理想的(我将尽我所能),我想要一个例程,它说..该约会有6次出现,这是每次出现的所有TDateTimes的数组。
请注意,所有这些代码都可以正常工作。我只需要帮助填写代码的BOTTOM部分以构建循环模式。
代码片段---并非按要求显示所有代码...
访问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
最佳答案
找出答案...。
这是我编写的例程,将从MinDate到MaxDate,并进行测试以查看约会是否在该日期存在。这是我可以重复工作的唯一方法。
procedure IdentifyOutlookRecurrences(Appt: Variant; EmailID: Integer; MinDateAllowed, MaxDateAllowed: TDateTime);
var
recurStart, recurEnd: TDateTime;
RP: Variant;
dt: TDate;
PatternEndDate: TDate;
TestAppt: Variant;
year, month, day, hour, minute, second, ms: Word;
CheckDateTime: TDateTime;
OccurrenceEndDate: TDateTime;
OccurrenceNumber: Integer;
begin
if Appt.IsRecurring then
begin
RP := Appt.GetRecurrencePattern;
DebugIt('Recurring Appt:', Appt.Subject);
// Get the date range for our occurrences
recurStart := RP.PatternStartDate;
recurEnd := RP.PatternEndDate;
DebugIt('Recur Start:End', DateToStr(recurStart) + ':' + DateToStr(recurEnd));
DebugIt('RecurPattern Start Time', DateTimeToStr(RP.StartTime));
// Identify the end point for looping...
if recurEnd < MaxDateAllowed then
PatternEndDate := recurEnd
else
PatternEndDate := MaxDateAllowed;
// Get the minimum date allowed...
dt := trunc(MinDateAllowed);
DecodeDate(dt, year, month, day);
DecodeTime(RP.StartTime, hour, minute, second, ms);
OccurrenceNumber := 0;
repeat
DecodeDate(dt, year, month, day);
CheckDateTime := EncodeDateTime(year, month, day, hour, minute, second, 0);
DebugIt('Check for recurrance', DateTimeToStr(CheckDateTime));
// Now check it the appointment exists.
try
TestAppt := RP.GetOccurrence(CheckDateTime);
OccurrenceEndDate := CheckDateTime + (RP.Duration / 1440);
DebugIt('Appt Recurrence *** IS *** found', DateTimeToStr(CheckDateTime));
// Now write it to the database
InsertApptIntoDB(Appt, EmailID, OccurrenceNumber, CheckDateTime, OccurrenceEndDate);
Inc(OccurrenceNumber);
except
DebugIt('Appt Recurrence *** NOT *** found', DateTimeToStr(CheckDateTime));
end;
// Increment our date
dt := dt + 1;
until dt > PatternEndDate;
end;
end;
DebugIt只是我使用的一个日志记录例程...
关于delphi - delphi-需要读取所有重复出现的Outlook Appt,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8565402/