Firemonkey OSX在下载期间更新进度条

时间:2012-02-26 18:39:42

标签: macos delphi progress-bar indy firemonkey

正在更新的进度条显示在Windows中。在OSX中,显示了进度条,但没有看到进度条移动。

见下面的代码。

procedure TForm1.Button1Click(Sender: TObject);
var
  m : TMemoryStream;
begin

   IdHTTP1.OnWork:= HttpWork;
  m := TMemoryStream.Create;

  IdHTTP1.Get('http://www.example.com/pictures.zip', m);

  m.SaveToFile('/users/demo/pictures.zip');
  m.Free;

end;

procedure TForm1.HttpWork(ASender: TObject; AWorkMode: TWorkMode;
  AWorkCount: Int64);
var
  Http: TIdHTTP;

  ContentLength: Int64;

  Percent: Integer;
begin
  Http := TIdHTTP(ASender);

  ContentLength := Http.Response.ContentLength;

  Percent := 100 * AWorkCount div ContentLength;

  ProgressBar1.Value := Percent;

end;

如何在OSX中更新进度条?

1 个答案:

答案 0 :(得分:2)

以下是我的代码中的内容,它适用于Windows和Mac:

Percent := 100 * AWorkCount div ContentLength;
frmDownloadProgress.ProgressBar1.Value := Percent;
Application.ProcessMessages;
如果TIdHTTP组件在主线程上,则

Application.ProcessMessages是更新进度条的关键。