2012-03-16 95 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更新。