Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
delphi-需要读取定期Outlook应用程序的所有事件_Delphi_Com_Outlook_Appointment_Ole Automation - Fatal编程技术网

delphi-需要读取定期Outlook应用程序的所有事件

delphi-需要读取定期Outlook应用程序的所有事件,delphi,com,outlook,appointment,ole-automation,Delphi,Com,Outlook,Appointment,Ole Automation,使用Delphi通过COM读取Outlook约会。。。 代码运行良好,定期约会除外。 我读到的每一篇文章都说,我需要使用RecurrencePattern和GetOccurse,确定下一次约会应该在哪里,然后尝试获得它,看看它是否失败。。。这似乎是一种非常“笨拙”的方式 有人写过这样的东西吗?显然,专家交换上有一些代码,但我没有订阅。。。找不到其他东西了 理想情况下(我会尽我所能),我希望有一个惯例,说。。此约会有6次出现,下面是每次出现的所有TDateTimes的数组 请注意,所有这些代码都可

使用Delphi通过COM读取Outlook约会。。。 代码运行良好,定期约会除外。 我读到的每一篇文章都说,我需要使用RecurrencePattern和GetOccurse,确定下一次约会应该在哪里,然后尝试获得它,看看它是否失败。。。这似乎是一种非常“笨拙”的方式

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

理想情况下(我会尽我所能),我希望有一个惯例,说。。此约会有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);
在浏览所有约会时

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;
procedure identificationoutlookrecurrences(Appt:Variant;EmailID:Integer;MinDateAllowed,MaxDateAllowed:TDateTime);
变量
RecursStart,Recurrend:TDateTime;
RP:变异;
dt:TDate;
模式结束日期:TDate;
TestAppt:变体;
年、月、日、时、分、秒,ms:Word;
CheckDateTime:TDateTime;
发生日期:TDateTime;
发生次数:整数;
开始
如果应用程序正在执行,则
开始
RP:=Appt.GetRecurrencePattern;
DebugIt('循环应用:',应用主题);
//获取事件的日期范围
递归开始:=RP.PatternStartDate;
recurEnd:=RP.PatternEndDate;
DebugIt('recurStart:End',DateToStr(recurStart)+':'+DateToStr(recurrend));
DebugIt('RecurPattern Start Time',DateTimeToStr(RP.StartTime));
//确定循环的终点。。。
如果recurEndpatterneddate;
结束;
结束;

DebugIt只是我使用的一个日志例程…

发布一个代码示例,至少提供一点上下文。提及您正在使用的接口(ISomething或ISomethingElse)。您实际上不需要专家交换成员资格。如果你能在谷歌上找到你想要的页面,点击链接并滚动到页面底部。当E-E从谷歌获得链接时,它会显示整个页面,包括答案。(如果它不这样做,答案将无法搜索,E-E将比它现在更没有用处。)奇怪。我在StackOverflow的链接上试过了,但没有得到答案。当我从谷歌搜索时,我得到了答案。。。一旦我看到了答案,它就不是我所希望的…+1,因为我发布了一些带有代码示例的上下文。
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;