Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my marquee progress bar not animate?

Tags:

delphi

I'm doing an application which has to communicate over tcp / ip. This program has one parameter modal form, which gets the IP of the server, the data needed, and test button to test the connection. That test button calls a function that checks if the server is active, and I would like to show a form with the typical progress bar with pbstMarquee style, indicating that you are trying to make the connection. this is the code of the test button:

procedure TFormConfiguracion.ButtonTestClienteClick(Sender: TObject);
begin
   if TestTCPClient(EdIPCliente.Text, EdPasswordProtocolo.Text, EdPuertoCliente.Value,
   self) then  
   begin    
     MensajeInformacion('Conexión con el Servidor Establecida con Exito!',''); //Ok
   else
   begin    
     MensajeError('Error al Conectar con el Servidor!',''); //Error
   end;
 end;

the code of the function TestTCP:

function TestTCPClient(Host,Password: String; Puerto: Integer; AOwner: TComponent): 
Boolean;
var
  TCPCliente: TIdTCPClient;
  textoEnvio: String;
begin
  TCPCliente := TIdTCPClient.Create(nil);
  Result := False;
  TCPCliente.Host := Host;
  TCPCliente.Port := Puerto;
  TCPCliente.ConnectTimeout := 20000;
  textoEnvio := Trim(Password)+'|TEST|#';
  try
    ShowFormCompConexion(AOwner, 'Intentando establecer conexión con el equipo   
    '+Host+'...'); //Trying to connect
    TCPCliente.Connect;
    TCPCliente.Socket.ReadTimeout := 10000;
    TCPCliente.Socket.WriteLn(textoEnvio, TEncoding.ANSI);
    if (TCPCliente.Socket.ReadLn(TEncoding.ANSI) = 'OK#') then
      Result := True;
    CloseFormCompConexion;
 except
   on E : Exception do
   begin
     CloseFormCompConexion;
     Exit;
    end;

  end;
end;

and the code of the function that displays the form with the progress bar:

procedure ShowFormCompConexion(AOwner: TComponent; Dato: String);
begin
  Form_CompConexion := TFormCompConexion.Create(AOwner);
  Form_CompConexion.LbDato.Caption := Dato;
  Form_CompConexion.Show;
  Form_CompConexion.Repaint;
end;

The problem is that this form remains inactive, I mean does not move the progress bar, it's like the wait for her to finish the process. I tried to put a gif, and nothing and no one lets me edit a Tedit ....

sorry for my English

like image 900
elcharlie Avatar asked Jan 25 '26 19:01

elcharlie


1 Answers

The progress bar needs the GUI thread to service its message queue. The fact that the progress bar does not refresh indicates that the GUI thread is not servicing its queue.

The reason that the queue is not being serviced is that the GUI thread is busy blocking on the socket communication. Since Indy uses blocking protocols there is simply no way to get around this issue so long as you use Indy from the GUI thread.

The solution? Put your blocking communications in a different thread. That allows you to service the GUI thread's message queue.

like image 61
David Heffernan Avatar answered Jan 27 '26 09:01

David Heffernan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!