olinaliu 2015-06-15 15:07 采纳率: 100%
浏览 1704
已采纳

delphi 里面 IShellItem是如何使用的。

图片说明
提示未定义IShellItem ,不知道是那个头文件未引用,
系统是Win7,
delphi7和delphixe2都试过,头文件引用了ShellAPI, ComObj还是不行;

  • 写回答

3条回答 默认 最新

  • WorldMobile 2015-06-16 00:18
    关注

    应该是ShlObj;

    给你段代码参考

    uses ActiveX, ComObj, ShlObj;

    function TForm1.CopyItem(const aSrcItem, aDest, aNewName: string): HRESULT;
    const
    CLSID_FileOp: TGUID = '{3ad05575-8857-4850-9277-11b85bdb8e09}';
    var
    lFileOperation: IFileOperation;
    psiFrom: IShellItem;
    psiTo: IShellItem;
    begin
    //
    // Initialize COM as STA.
    //
    Result := CoInitializeEx(nil, COINIT_APARTMENTTHREADED or COINIT_DISABLE_OLE1DDE);
    if Succeeded(Result) then
    begin

    //
    // Create the IFileOperation interface
    //
    Result := CoCreateInstance(CLSID_FileOp, nil, CLSCTX_ALL, IFileOperation,
                          lFileOperation);
    if Succeeded(Result) then
    begin
      //
      // Set the operation flags. Turn off all UI from being shown to the
      // user during the operation. This includes error, confirmation,
      // and progress dialogs.
      //
      Result := lFileOperation.SetOperationFlags(FOF_NO_UI);
      if Succeeded(Result) then
      begin
        //
        // Create an IShellItem from the supplied source path.
        //
        Result := SHCreateItemFromParsingName(aSrcItem,
                                         nil,
                                         IShellItem, psiFrom);
        if Succeeded(Result) then
        begin
          if aDest <> '' then
          begin
            //
            // Create an IShellItem from the supplied
            // destination path.
            //
            Result := SHCreateItemFromParsingName(aDest,
                                             nil,
                                             IShellItem, psiTo);
          end;
    
          if Succeeded(Result) then
          begin
            //
            // Add the operation
            //
            Result := lFileOperation.CopyItem(psiFrom, psiTo, aNewName, nil);
    
            psiTo := nil;
          end;
    
          psiFrom := nil;
        end;
    
        if Succeeded(Result) then
        begin
          //
          // Perform the operation to copy the file.
          //
          Result := lFileOperation.PerformOperations;
        end;
      end;
    
      //
      // Release the IFileOperation interface.
      //
      lFileOperation := nil;
    end;
    
    CoUninitialize;
    

    end;
    end;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog