2

I'm working with Delphi2010 . When I run the code with Outlook 2003 SP3, I get no errors but on another pc with outlook2007 i get an error 'Invalid Function error'.

const
  olMailItem = 0;
  olFolderInbox = $00000006;

var  
  Outlook: OleVariant;
  oNameSpace:  OleVariant;
  oFolder: Olevariant;
  oMailItem: Variant;
  oUserProperty: Olevariant;
begin

  try
    Outlook := GetActiveOleObject('Outlook.Application');
  except
    Outlook := CreateOleObject('Outlook.Application');
  end;

  oNameSpace := Outlook.GetNamespace('MAPI') ;
  oFolder:= oNameSpace.GetDefaultFolder(olFolderInbox);


  oMailItem := Outlook.CreateItem(olMailItem);
  ...
  oUserProperty:= oMailItem.UserProperties.Add('RetrieveCode', 1); //--> get error on Outlook2007
  oUserProperty.Value:=ARetrieveCode;
  ...
end;

When I use redemption I get the same error for Outlook2007 Can someone point the right direction to solve this problem?

I catch the error with eurekalog:

; ComObj (Line=0 - Offset=0)
; --------------------------
00538469  mov     eax, dword ptr [EOleSysError]
0053846E  call    ComObj
00538473  mov     esi, eax
00538475  cmp     dword ptr [ebp-$04], +$00
00538479  jz      ComObj
0053847B  push    dword ptr [ebp-$04]
0053847E  mov     eax, esi
00538480  jmp     System
00538485  jmp     ComObj
00538487  mov     eax, esi
00538489  call    System                         ; <-- EXCEPTION
0053848E  xor     eax, eax
00538490  pop     edx
00538491  pop     ecx
00538492  pop     ecx
00538493  mov     fs:[eax], edx
00538496  push    $005384B0                      ; '^[‹å]Â.'
0053849B  lea     eax, [ebp-$10]
0053849E  mov     edx, $00000003                 ; ''...
005384A3  call    System
005384A8  ret
4

1 回答 1

0

我已将我的代码从后期绑定更改为早期绑定,以检查我是否收到相同的错误。我将库导入到 OutLook_TLB.pas 并在单元的使用中添加 Outlook_TLB。

uses
  ...,
  Outlook_TLB;

function SendOutLookMail ...
var
  ...
  MyOutlook: Outlook_TLB.OutlookApplication;
  MyMailItem: Outlook_TLB.MailItem;
  MyUserProperty: Outlook_TLB.UserProperty;
begin
  ...
  MyOutlook:= Outlook_TLB.CoOutlookApplication.Create;
  MyMailItem:= MyOutlook.CreateItem(olMailItem)as MailItem;
  MyUserProperty:= MyMailItem.UserProperties.Add('RetrieveCode', 1, EmptyParam, EmptyParam) as UserProperty;
  MyUserProperty.Value:= ARetrieveCode;
  MyMailItem.Recipients.Add(AFrom);
  MyMailItem.To_:= ATo;
  MyMailItem.Subject := ASubject+' early/late-bound';
  MyMailItem.Body := ABody;
  MyMailItem.Send;
end;

当我运行代码时,我在装有 Outlook2007 的电脑上没有任何错误。所以早期绑定到对象解决了我的问题。

于 2012-08-27T11:14:21.923 回答