简体   繁体   English

使用Delphi XE2下载

[英]tdownload using Delphi XE2

Hoping for help with TDownloadURL Using this code that saves downloaded file. 希望获得有关TDownloadURL的帮助使用此代码可以保存下载的文件。 Using Delphi XE2. 使用Delphi XE2。 want to save download to memory/tstringlist not file. 想要将下载文件保存到内存/字符串列表而不是文件。 how to do this without adding component? 如何在不添加组件的情况下做到这一点? Thank you! 谢谢!

notfound:=false;
dl := TDownloadURL.Create(self);
  try
    dl.URL := url;
    dl.FileName := execpath+'apic1.csv'; dl.ExecuteTarget(nil); dl.Free;
  except
    dl.Free;
    notfound:=true;
  end;

The TDownLoadURL from ExtActns unit can't do anything more than downloading to a file. ExtActns单元的TDownLoadURL除了下载到文件无能为力 It's ExecuteTarget method is implemented like that. 它的ExecuteTarget方法就是这样实现的。 If I were you, I would use Indy. 如果我是你,我会使用印地。 It's simple: 这很简单:

uses
  IdHTTP;

var
  Client: TIdHTTP;
  Stream: TStream;
begin
  Client := TIdHTTP.Create;
  try
    Stream := TMemoryStream.Create;
    try
      Client.Get(URL, Stream);
      { ← process Stream somehow }
    finally
      Stream.Free;
    end;
  finally
    Client.Free;
  end;
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM