2012-08-24 13 views
2

我正在使用Delphi2010。 当我使用Outlook 2003 SP3运行代码时,我没有收到任何错误,但在Outlook2007的另一台电脑上出现错误“无效的函数错误”。Outlook2007中的UserProperties.Add获取无效函数错误

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; 

当我使用赎回我得到Outlook2007 同样的错误有人能指向正确的方向来解决这个问题?

我捕获错误与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 
+1

调试迟到的COM可能会很棘手。你有没有尝试过早绑定?可能会得到更多信息错误。 –

+0

你为什么在2007年使用Redemption?这不是必需的。 –

+0

在该公司我们使用outlook2003和一些人outlook2007。我们使用赎回,因为我得到了outlook的安全对话。 – Ravaut123

回答

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的电脑上没有任何错误。 因此,尽早绑定对象来解决我的问题。

相关问题