从代码启动Outlook,然后手动启动,会给类别名称不匹配

时间:2015-04-15 13:30:18

标签: delphi outlook delphi-xe2 ole outlook-2007

  1. 如果我手动启动Outlook然后运行通过OLE与其对话的程序,则所有带有颜色的(重命名)类别都可见:
  2. enter image description here

    1. 如果我没有手动启动Outlook,但让它从代码启动,然后手动启动以及,我突然想念我重命名的类别信息:
    2. enter image description here

      在个人约会中,我们看到重命名的类别仍然存在:

      enter image description here

      但这些类别名称与某些主列表之间的链接' (?)定义颜色似乎缺失。

      幸运的是我的代码似乎没有问题,它为约会检索的类别是重命名的。

      但我想改变第2点下的行为 - 当我的程序运行时我打开Outlook它非常适合调试,如果我在Outlook中看到正确的数据; - )

      以下是启动Outlook的代码:

      function TDataModuleSyncOutlook.ConnectToOutlook(AUserSMTP: String = ''): Boolean;
      var
         lRecipient,
         lVar      : OleVariant;
         lLog,
         lLoginSMTP: String;
      begin
         Result      := false;
         FWasCreated := False;  // Breakpoint 'Ignore subsequent exceptions'
         try
            FOutlookApp := GetActiveOleObject(scxOutlookApp);         // Application object. This code fails if Outlook is not yet running...
            Result := True;
         except
            try
               FOutlookApp := CreateOleObject(scxOutlookApp);         // ... and then this creates the Outlook instance 
               FWasCreated := True;
               Result := True;
            except
               on E:Exception do TSyncLogger.LogError(E.Message);
            end;
         end;
         if Result then          // Breakpoint 'Handle subsequent exceptions'
         begin
            FNameSpace := FOutlookApp.GetNamespace(scxNameSpace);
            // Oplossing uit http://stackoverflow.com/questions/18053110/retrieve-outlook-logged-in-user-smtp-address-after-connecting-through-ole/
            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
            begin
               lLoginSMTP := FOutlookApp.Session.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress;
               TSyncLogger.LogDetail('Primary Exchange SMTP address detected as: ' + lLoginSMTP);
            end
            else
            begin
               TSyncLogger.LogError(sErrNoExchangeAccount);
               DisConnectFromOutlook;
               Exit;
            end;
            if LowerCase(AUserSMTP) <> Lowercase(lLoginSMTP) then
            begin   // Open shared calendar for different user. This does not apply in my test case
               lRecipient := FNameSpace.CreateRecipient(AUserSMTP);
               try
                  FCalendarFolder := FNameSpace.GetSharedDefaultFolder(lRecipient, olFolderCalendar);
                  lLog := Format('Logging in as different user (%s), created recipient for %s, GetSharedDefaultFolder folder path = %s',[AUserSMTP,lRecipient.Address,FCalendarFolder.FolderPath]);
                  TSyncLogger.LogAlways(lLog);
               except
                  on E:Exception do
                  begin
                     Result := false;
                     TSyncLogger.LogError(Format(sErrOpenGedeeldeAgenda,[AUserSMTP]));
                  end;
               end;
            end
            else   // ... otherwise open default calendar folder 
            begin
               FCalendarFolder := FNameSpace.GetDefaultFolder(olFolderCalendar);
               TSyncLogger.LogDetail('Opened default calendar folder, folder path = ' + FCalendarFolder.FolderPath);
            end;
         end;
         FOleInitialized := Result;
         if Result then TSyncLogger.LogDetail('Connected to Outlook') else TSyncLogger.LogAlways('Connection to Outlook failed');
      end;
      

      任何想法/建议该怎么做?

      其他信息:

      • Outlook 2007连接到Exchange 2013 RTM,在Win7-64下
      • 我为此计算机设置了多个邮件配置文件,用于连接到Exchange 2013的邮件配置文件设置为Outlook启动的默认配置文件。每次Outlook启动时(也来自代码)我都会收到提示输入密码。

1 个答案:

答案 0 :(得分:-1)

请注意,类别存储在每个商店的基础上。这两件商品都来自同一家商店吗?或者其中一个居住在委托邮箱中?