Delphi FMX TIdFTP onWork, onWorkBegin, onWorkEnd not working

355 Views Asked by At

I've been fighting with TIdFTP and Delphi FMX for a while and I don't get good results, so, I don't really know what to do.

So, the thing that I want to do is to show a ProgressBar while GETTING and POSTING with TIdFTP. I've seen some codes online, that I've adapted, but nothing works.

But the problem is not only that the ProgressBar doesn't work. The problem goes much further: I tried to make an easier functionality, that only makes Visible:= true and Visible:= false when the IdFTP is working.

So, I thought: If I make a get or a post, the TIdFTP events OnWorkBegin, OnWork and OnWorkEnd should capture the action and make it visible/invisible.

So, the code I put was that:

procedure TF_FTP.IdFTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Int64);
begin
  ProgressBar1.Visible := true;
end;
procedure TF_FTP.IdFTP1Work(ASender: TObject; AWorkMode: TWorkMode;
  AWorkCount: Int64);
begin
  ProgressBar1.Visible := true; 
end;

and

procedure TF_FTP.IdFTP1WorkEnd(ASender: TObject; AWorkMode: TWorkMode);
begin
  ProgressBar1.Visible := false;
end;

This is the code I use to make the FTP request:

procedure ActualitzaInfo(ruta_loc, ruta_rem: String);
var myFile: TextFile;
    data: String;
begin
  with F_FTP do
  begin

    // Connection
    IdFTP1.Username := '<my-user>';
    IdFTP1.Password := '<my-password>';
    IdFTP1.Host := '<my-host>';

    // Clear lists
    LB_Curts.Items.Clear;
    LB_Llargs.Items.Clear;

    try
      // Connect
      IdFTP1.Connect;
      mida_ftp := IdFTP1.Size(ruta_rem);
      try
        //GET
        IdFTP1.Get(ruta_rem, ruta_loc, True, False);
      finally
        IdFTP1.Disconnect;
      end;
      ShowMessage('Downloaded!');
    except
      ShowMessage('Error downloading!');
      exit;
    end;

    //Fill lists
    CarregaControls(ruta_loc);
  end;
end;

What happened is, at the first get, the ProgressBar was visible because in the Form Design it is set as Visible. When it finishes, the ProgressBar gets invisible. Ok, well. But when I try to make another get or post, the ProgressBar never appears again.

If I make the ProgressBar invisible at the Form design, it never shows up.

I tried putting the Visible/Invisible on other IdFTP events, as onConnected-onDisconnected, onBeforeGet-onAfterGet, ... nothing seems to work. In addition, when I'm downloading the files, the Form freezes.

I don't know what is happening, I'm running on Android64.

Thank you in advance.

0

There are 0 best solutions below