UserProperties.Add en Outlook 2007 obtiene un error de función no válida

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'.

  olMailItem = 0;
  olFolderInbox = $00000006;

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

    Outlook := GetActiveOleObject('Outlook.Application');
    Outlook := CreateOleObject('Outlook.Application');

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

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

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

preguntado el 24 de agosto de 12 a las 08:08

Debugging late bound COM can be tricky. Have you tried early bound instead. May get more informative errors. -

Why are you using Redemption on 2007? It's not needed there. -

In the company we use outlook2003 and some people outlook2007. We use redemption because i get the securitydialog of outlook. -

early bound is this then CreateOleObject('Outlook.Application') and late-bound is import the outlook library? -

Ok, I will import the outlook library to outlook_tlb.pas. -

1 Respuestas

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.


function SendOutLookMail ...
  MyOutlook: Outlook_TLB.OutlookApplication;
  MyMailItem: Outlook_TLB.MailItem;
  MyUserProperty: Outlook_TLB.UserProperty;
  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.To_:= ATo;
  MyMailItem.Subject := ASubject+' early/late-bound';
  MyMailItem.Body := ABody;

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.

Respondido 27 ago 12, 12:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.