OLECheck是来包装CoCreateInstance和其他OLE函数的调用。OLE函数一般返回名为HResult的变量。该变量成功是通常为零,失败时返回Activex.pas中声明来确定标准错误值的负值。Olecheck就会尝试着把Hresult的数值转换为可读的字符串,接着出现异常,并且把字符串显示出来。如果不想用OLECheck,也可以用函数Succeeded或者Failed检查来调用结果。如:
var
  hr: HResult
begin
 hr := MYOLEFunc;
 if SUCCEEDED(hr) then ...

解决方案 »

  1.   

    可否再详细一点呢?下面的语句究竟是什么意思?
    ..
    FIDesktopFolder: IShellFolder;
    NewPIDL: PItemIDList;
    ..
    OLECheck(SHGetDesktopFolder(FIDesktopFolder));
    ..
    OLECheck(SHGetSpecialFolderLocation(
                                        Application.Handle,
                                        CSIDL_DRIVES,
                                        NewPIDL)
                                         );
    SetPath(NewPIDL);请各位帮帮忙?
      

  2.   

    OLECheck的作用主要就是检查OLE函数了。
    至于你提到内容在ShlObj单元(源码)有详细描述
    我的理解大概是这样的:
    ..
    //得到一个IShellFolder接口,SHGetDesktopFolder相当于CoCreateInstance函数
    OLECheck(SHGetDesktopFolder(FIDesktopFolder));
    ..
    //通过CSIDL_DRIVES得到一个PItemIDList变量
    OLECheck(SHGetSpecialFolderLocation(
                                        Application.Handle,
                                        CSIDL_DRIVES,
                                        NewPIDL)
                                        );
    具体细节我不是很清楚,你还是自己看吧,注释很详细。
      

  3.   

    1.Setting up a transaction object on the client side
    A client base application can control transaction context through the ITransactionContextEx interface. The following code example shows how a client application uses CreateTransactionContextEx to create the transaction context. This method returns an interface to this object. 
    This example wraps the call to the transaction context in a call to OleCheck which is necessary because the CreateInstance method is not declared as safecall. procedure TForm1.MoveMoneyClick(Sender: TObject);begin
      Transfer(CLASS_AccountA, CLASS_AccountB, 100);
    end;
    procedure TForm1.Transfer(DebitAccountId, CreditAccountId: TGuid; Amount: Currency);
    var
      TransactionContextEx: ITransactionContextEx;
      CreditAccountIntf, DebitAccountIntf: IAccount;
    begin
      TransactionContextEx := CreateTransactionContextEx;
      try
        OleCheck(TransactionContextEx.CreateInstance(DebitAccountId,
          IAccount, DebitAccountIntf));
        OleCheck(TransactionContextEx.CreateInstance(CreditAccountId,      IAccount, CreditAccountIntf));
        DebitAccountIntf.Debit(Amount);
        CreditAccountIntf.Credit(Amount);
      except
        TransactionContextEx.Abort;
        raise;
      end;
      TransactionContextEx.Commit;
    end;
    2.Setting up a transaction object on the server side
    To control transaction context from the MTS server side, you create an instance of ObjectContext. In the following example, the Transfer method is in the MTS object. In using ObjectContext this way, the instance of the object we are creating will inherit all the transaction attributes of the object who is creating it. We wrap the call in a call to OleCheck because the CreateInstance method is not declared as safecall. procedure TAccountTransfer.Transfer(DebitAccountId, CreditAccountId: TGuid; Amount: Currency);
    var
      CreditAccountIntf, DebitAccountIntf: IAccount;
    begin
      try
        OleCheck(ObjectContext.CreateInstance(DebitAccountId,
          IAccount, DebitAccountIntf));
        OleCheck(ObjectContext.CreateInstance(CreditAccountId,
          IAccount, CreditAccountIntf));
        DebitAccountIntf.Debit(Amount);
        CreditAccountIntf.Credit(Amount);
      except
        DisableCommit;
        raise;
      end;
      EnableCommit;
    end;