2012-03-16 119 views
2

如何下载过在firemonkey URL是在Windows和MacOS X系统都兼容的文件?下载应该通过https。Delphi XE2 Firemonkey文件下载?

+3

印地支持Windows和OSX,所以尽量使用'TIdHTTP'组件,顺便说一句,互联网是充分了解如何使用它的样本。 – RRUZ 2012-03-16 06:44:32

回答

4

一个与XE2提供的印地支持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更新。