R
R
Romanson2017-06-14 13:20:01
Delphi
Romanson, 2017-06-14 13:20:01

Why is thread not working in Delphi FMX?

Hello toaster! I'm trying to implement a cyclic download of a file by means of a stream. because the form is needed constantly in access, externally the base file must be constantly loaded.

type
  ThreadHTTP = class(TThread)
  private

  public
    Stream: TMemoryStream;
    i: integer;

    procedure Execute; override;
    procedure ShowResult;
  end;

{$R *.fmx}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Timer1.Enabled := true;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin

end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  MyHTTP: ThreadHTTP;
begin
  ProgressBar1.Value := 0;
  MyHTTP := ThreadHTTP.Create(False);
end;

{ ThreadHTTP }

procedure ThreadHTTP.Execute;
var
  j: integer;
begin
  inherited;
  i := 0;
  j := 0;
  Stream := TMemoryStream.Create;
  Form1.IdHTTP1.Get('http://сайт/base.txt', Stream);
  Form1.ProgressBar1.Max := Stream.Size;
  while j <= Stream.Size do
  begin
    inc(i);
    Synchronize(ShowResult);
    inc(j);
    Form1.ProgressBar1.Value := Form1.ProgressBar1.Value + 1;
  end;
  // Stream.SaveToFile('C:\base.txt');
  Stream.SaveToFile(tpath.getdownloadspath + '/base.txt');

  // Form1.Memo1.Lines.LoadFromFile('C:\base.txt');
  Form1.Memo1.Lines.LoadFromFile(tpath.getdownloadspath + '/base.txt');
  Stream.Free;
end;

procedure ThreadHTTP.ShowResult;
begin
  Form1.Label1.Text := IntToStr(i) + ' kbs';
end;

everything works fine on the PC and when changing the base from outside everything works fine in real time. in the ANDROID system does not want to load the file into some. Progress bar does not run. The file does not download or save. What is the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question