红鱼儿

用kbmMW FileClient.PutFile上传文件要这么干才对!
procedure Tmainform.Button5Click(Sender: TObject);
var
  cnt: Integer;
  PutFileOK: boolean;
begin
  cnt:=0;
  while True do
  begin
    cnt:=cnt+1;
    try
      kbmMWFileClient1.PutFile('.\1.png', '1.png');
    except
      on e: Exception do
      begin
//        if kbmMWFileClient1.SameFile('.\1.png', '1.png') then
//          break;
      end;
    end;
    PutFileOK := False;
    try
      PutFileOK := kbmMWFileClient1.SameFile('.\1.png', '1.png');
    except
      PutFileOK := False;
    end;
    if PutFileOK or (cnt>5) then
      break;
  end;

end;

上面的代码,是改造后的,我上传一个文件,然后,比较本地与远程文件是否相同,不同,则重新执行PutFile,相同,则跳出循环,完成文件上传。如果不用try except来捕获PutFile可能产生的异常,由不会执行SameFile来比较文件,而是直接跳出循环。

posted on 2021-03-30 21:32  红鱼儿  阅读(170)  评论(0编辑  收藏  举报