gpt4 book ai didi

delphi - Delphi XE2 Firemonkey文件下载?

转载 作者:行者123 更新时间:2023-12-03 18:28:20 25 4
gpt4 key购买 nike

如何在Windows和MacOS X兼容的firemonkey中的URL上下载文件?下载应通过https。

最佳答案

XE2随附的Indy支持Mac OSX。
参见:Does Delphi XE2 FireMonkey support Indy for cross-platform apps?

这是工作流程:

File-> New (Firemonkey HD app)
Add Mac OSX as target platform
Place a TIdHTTP component on the form
Place a TEdit on the form


下面的代码应该得到一些基本的结果

type
TForm16 = class(TForm)
IdHTTP1: TIdHTTP;
Edit1: TEdit;
procedure Edit1Enter(Sender: TObject);
public
MyFile: TFileStream;
end;

implementation

{$R *.fmx}

procedure TForm16.Edit1Enter(Sender: TObject);
var
Success: boolean;
begin
if (MyFile = nil) then try
//Correct path handling to be added
//filename should be extracted from the url etc etc.
MyFile:= TFileStream.Create('Test.dat',fmCreate);
Success:= true;
except
Success:= false;
end;
if Success then begin
IdHTTP1.Get(Edit1.Text, MyFile);
//do stuff with the file
end;
end;


一个建议,请确保首先与 http一起使用, https设置起来很棘手。
还要确保您安装了最新版本的Indy和最新的XE2更新。

关于delphi - Delphi XE2 Firemonkey文件下载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9731409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com