zoukankan      html  css  js  c++  java
  • DELPHI IDHTTP下载

    type
      THttpThread = class(TThread)
      private
        FIdHTTP: TIdHTTP;
        FUrl: string;
        FSavePath: string;
        procedure Down(Url: string; SavePath: string);
      public
        constructor Create(CreateSuspended: Boolean; Url: string; SavePath: string);
        destructor Destroy; override;
        procedure Execute; override;
      end;

    { THttpThread }

    constructor THttpThread.create(CreateSuspended: Boolean; Url: string; SavePath: string);
    begin
      inherited Create(CreateSuspended);
      FreeOnTerminate := True;
      FUrl := Url;
      FSavePath := SavePath;
      FIdHTTP := TIdHTTP.Create(nil);
    end;

    destructor THttpThread.Destroy;
    begin
      FIdHTTP .Free;
      inherited;
    end;

    procedure THttpThread.Down(Url: string; SavePath: string);
    var
      Stream: TMemoryStream;
    begin
      BegTime := GetTickCount;
      Stream := TMemoryStream.Create;
      try
        try
          FIdHTTP.Get(Url, Stream);
        finally
          DeleteUrlCacheEntry(PChar(Url));
        end;
      except
        MessageBox(0, '网络出错', '提示', MB_ICONQUESTION);
        Stream.Free;
        Exit;
      end;

      Stream.SaveToFile(SavePath);
      Stream.Free;
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    var
      HttpThread1: THttpThread;
      UrlPath: string;
    begin
      UrlPath := 'http://mirror1.2ccc.com/downloads/general/multimedia/Money2ChineseCapitalaovi888.rar';
      HttpThread1 := THttpThread.Create(False, UrlPath, 'C:\Test\1.Rar');
    end;

    procedure THttpThread.Execute;
    begin
      inherited;
      Down(FUrl, FSavePath);
    end;

  • 相关阅读:
    element-ui的气泡确认框
    ES6 检测数组中是否存在满足某些条件的元素实现方式
    P6788 「EZEC-3」四月樱花
    Codeforces Global Round 10(CF1392)
    Ynoi2019模拟赛
    谷粒学院项目分享(源码+资料+课件)全部齐全
    安装最新版NUXT
    LibreOJ #6284
    LibreOJ #6283
    LibreOJ #6282
  • 原文地址:https://www.cnblogs.com/chengxin1982/p/1576946.html
Copyright © 2011-2022 走看看