function   TFolderFile_Frm.CopyDir(FromDir,   ToDir:   string):   boolean;
var T   :   TSHFileOpStruct;  //文件复制
begin
        T.Wnd:=Application.Handle;
        T.wFunc:=FO_COPY   ;
        T.pFrom:=Pchar(FromDir);
        T.pTo:=pchar(ToDir);
        T.hNameMappings:=nil;
        T.lpszProgressTitle:=nil;
        T.fFlags:=FOF_NOCONFIRMATION;
    SHFileOperation(T);
    result   :=   true;
end;
//----------为什么用1就不能复制,用2就可以复制-----
procedure TFolderFile_Frm.Button1Click(Sender: TObject);
VAR  FromDir1,   ToDir1  :   string ;
begin
   CreateDirectory(PChar(ExtractFilePath(ParamStr(0))+Edit1.Text ),nil);
   FromDir1 :=  getcurrentdir() ;
   FromDir1 := FromDir1 + '\Test.exe' ;
   
   //1//ToDir1   := PChar( ExtractFilePath(ParamStr(0))+123 ) ;
   //2//ToDir1   :='D:\1030\MyFunction_0529_1\Carrier_RtuOperation\bin\123'
   
   SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_IDLIST+SHCNF_FLUSH,nil,nil); //刷新   if CopyDir(FromDir1,   ToDir1 ) then
end;

解决方案 »

  1.   

    brightyang 跟踪过了,字符串是一样的
    我也想过了是不是没有刷新,后我刷新了,又想是不是没有延时,后也延时了
    还是不行,就问是什么?
      

  2.   

      Function Copy_Dir(SourceDir,DestDir:String;nLx:Integer):Boolean;
      Var
        Opstruc: TshFileOpStruct;
        frombuf,tobuf: Array[0..128] of Char;
      begin
        FillChar(frombuf,Sizeof(frombuf),0);
        FillChar(tobuf,Sizeof(tobuf),0);
        StrPcopy(frombuf,SourceDir);
        Case nLx of
             1:
               StrPcopy(tobuf,DestDir);
        end;
        With Opstruc Do
        Begin
             Wnd:=0;
             Case nLx of
                 1: wFunc:=FO_COPY;
                 2: wFunc:=FO_DELETE;
                 Else wFunc:=FO_COPY;
             end;
             pFrom:=@frombuf;
             pTo:=@tobuf;
             fFlags:=FOF_NOCONFIRMATION;
             fAnyOperationsAborted:=False;
             hNameMappings:=Nil;
             lpszProgressTitle:=Nil;
        end;
        try
             ShFileOperation(OpStruc);
             Result:=True;
        except
             Result:=False;
        end;
      

  3.   

    谢谢,你hongqi162 ,
    为什么,你的函数可以,我的函数就不可以呢?