delphi - 需要读取所有出现的 Recurring Outlook Appt

标签 delphi com outlook appointment ole-automation

使用Delphi通过COM读取Outlook约会... 代码工作正常,但定期约会除外。 我读到的所有内容都说我需要使用 RecurrencePattern 和 GetOccurrence 并确定下一个约会应该在哪里,然后尝试获取它,看看它是否失败......这似乎是一种真正的“拼凑”方式。

有人写过这样的东西吗?显然,专家交换上有一些代码,但我没有在那里订阅......找不到其他任何东西。

理想情况下(我会采取我能得到的),我想要一个例程,它说..此约会有 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

最佳答案

找到答案了...... 这是我编写的一个例程,将从 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 - 需要读取所有出现的 Recurring Outlook Appt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8565402/

相关文章:

Java、Jacob 和 Microsoft Outlook 事件 : Receiving "Can' t find event iid"Error

delphi - TabSheet不显示图像

delphi - Delphi 2010 中的代码完成速度是否有所提高?

c# - VBA 中自定义 COM 类中的 IntelliSense

visual-studio-2008 - .rgs文件中的注释的语法是什么

vba - Outlook VBA - 获取当前事件(或打开)电子邮件的详细信息

vba - Outlook VBA 代码错误

与 Delphi 7 相比,Delphi 2010 的 Canvas 透明度有何不同?

android - 如何在delphi firemonkey和android上使用抗锯齿

excel - 有没有办法阻止Excel自动将Application.ScreenUpdating设置为True