我现在要实现一个IDocHostUIHandler接口的类,接口中有这样
HRESULT FilterDataObject(
  IDataObject *pDO, IDataObject **ppDORet
);我的转换是:
function FilterDataObject(const pDO: IDataObject; var ppDORet: IDataObject): HRESULT;
这样是否正确?如果把var改成out,有什么不同?原接口中的ppDORet是一个**IDataObject类型,也就是指向IDataObject的指针的指针,那么在转换到Delphi函数时,通过var或者out能有效吗?盼复。

解决方案 »

  1.   

    不过别忘了COM里的方法都应该约定俗成是safecall的。
    function FilterDataObject(const pDO: IDataObject; var ppDORet: IDataObject): HRESULT;
    应该写为
    关于out,Delphi的文档中写的:
    Out Parameters
     
    An out parameter, like a variable parameter, is passed by reference. With an out parameter, however, the initial value of the referenced variable is discarded by the routine it is passed to. The out parameter is for output only; that is, it tells the function or procedure where to store output, but doesn't provide any input.
     
    For example, consider the procedure heading
     procedure GetInfo(out Info: SomeRecordType);
    When you call GetInfo, you must pass it a variable of type SomeRecordType:
     var MyRecord: SomeRecordType;
       ...
    GetInfo(MyRecord);
    But you're not using MyRecord to pass any data to the GetInfo procedure; MyRecord is just a container where you want GetInfo to store the information it generates. The call to GetInfo immediately frees the memory used by MyRecord, before program control passes to the procedure.
     
    Out parameters are frequently used with distributed-object models like COM and CORBA. In addition, you should use out parameters when you pass an uninitialized variable to a function or procedure