代码如下
var
  Form1: TForm1;
  Cancel: integer;
  iCount: Integer;
implementation{$R *.dfm}
function CopyProgress(
  TotalFileSize: LARGE_INTEGER; // 文件总大小,字节
  TotalBytesTransferred: LARGE_INTEGER; // 已复制的文件大小,字节
  StreamSize: LARGE_INTEGER; // 当前流的总字节数
  StreamBytesTransferred: LARGE_INTEGER; // 当前流已拷贝的字节数
  dwStreamNumber: DWORD; // 当前流序号
  dwCallbackReason: DWORD; // 回调函数的状态,见定义
  hSourceFile: THANDLE; // 来源文件句柄
  hDestinationFile: THANDLE; // 目标文件句柄
  lpData: Pointer // CopyFileEx 函数传递过来的参数
  ): DWORD; stdcall; // 回调函数的返回值,见定义
  var
  str:string;
begin
  Application.ProcessMessages;str:=floattostr((TotalBytesTransferred.QuadPart / TotalFileSize.QuadPart)* 100);
if pos('.',str)>0 then
beginApplication.ProcessMessages;
form1.listview3.Items[0].SubItems.strings[1]:=copy(str,1,pos('.',str)-1)+'%';
form1.ProgressBar1.Position:=strtoint(copy(str,1,pos('.',str)-1));
end
else
begin
Application.ProcessMessages;
form1.listview3.Items[0].SubItems.strings[1]:=str+'%';
form1.ProgressBar1.Position:=strtoint(str);
end;  Inc(iCount);
end; function star(): string;
var
  Src, Dest: string;
  str1:string;
begin
while 1=1 do
begin
   if form1.listview3.Items.Count>0 then
   begin
  if form1.listview3.Items[0].SubItems.strings[1] = '0%' then
  begin    iCount := 0;
    Cancel := 0;
    Src :=form1.listview3.Items[0].Caption;
    Dest := form1.listview3.Items[0].SubItems.strings[0];    if not FileExists(Src) then begin
    showmessage('文件不存在!');
    //Memo1.Text := '文件 ' + Src + ' 不存在!';
      Exit;
    end;    CopyFileEx(
      PChar(Src),
      PChar(Dest),
      @CopyProgress,
      nil,
      @Cancel,
      COPY_FILE_RESTARTABLE);
  end
  else
  if form1.listview3.Items[0].SubItems.strings[1] = '100%' then
  begin
  form1.listview3.Items[0].Delete;
  form1.ProgressBar1.Position:=0;
  end;
  end;
  sleep(100);
  end;
end;
CopyFileEx中有传递一个 @Cancel,参数,我要怎么把一个INTEGER赋值给它,并且在CopyProgress中调用这个值

解决方案 »

  1.   

      var 
         a,b:   Integer;   
          p:   Pointer;   
      begin   
          a   :=   12345;   
          p   :=   Pointer(a);   
          b   :=   Integer(p);   
    两者间可以互相转换的,强制类型转一下就行了
      

  2.   

    The CopyProgressRoutine function is called when a portion of a copy operation started by CopyFileEx is completed. This function is an application-defined callback routine.DWORD WINAPI CopyProgressRoutine(    LARGE_INTEGER TotalFileSize, // total file size, in bytes
        LARGE_INTEGER TotalBytesTransferred, // total number of bytes transferred
        LARGE_INTEGER StreamSize, // total number of bytes for this stream
        LARGE_INTEGER StreamBytesTransferred, // total number of bytes transferred for this stream
        DWORD dwStreamNumber, // the current stream
        DWORD dwCallbackReason, // reason for callback
        HANDLE hSourceFile, // handle to the source file
        HANDLE hDestinationFile, // handle to the destination file
        LPVOID lpData // passed by CopyFileEx 
       );
     ParametersTotalFileSizeThe total size of the file, in bytes.TotalBytesTransferredThe total number of bytes transferred from the source file to the destination file since the copy operation began.StreamSizeThe total size of the current file stream, in bytes.StreamBytesTransferredThe total number of bytes in the current stream that have been transferred from the source file to the destination file since the copy operation began.dwStreamNumberIdentifies the current stream. The stream number is 1 the first time CopyProgressRoutine is called.dwCallbackReasonSpecifies the reason that CopyProgressRoutine was called. This parameter can be one of the following values:Value Meaning
    CALLBACK_CHUNK_FINISHED Another part of the data file was copied.
    CALLBACK_STREAM_SWITCH Another stream was created and is about to be copied. This is the callback reason given when the callback routine is first invoked.
     hSourceFileIdentifies the source file.hDestinationFileIdentifies the destination filelpDataThe argument passed to CopyProgressRoutine by the CopyFileEx function.
      

  3.   

    楼主参照下这个例子
    http://vip.6to23.com/NowCan1/tech/copyex.htmCopyProgressRoutine只是个回调函数。