Question

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
Was it helpful?

Solution

I have change my code from late-bound to early-bound to check if I get the same error. I imported the library to OutLook_TLB.pas and add the Outlook_TLB in the uses of the unit.

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;

When I run the code, I don't have any error on a pc with Outlook2007. So an early bound to the object fixed my problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top