Ir al contenido


Foto

Usando más de 1 TTask para diferentes eventos


  • Por favor identifícate para responder
No hay respuestas en este tema

#1 Punzo

Punzo

    Member

  • Miembros
  • PipPip
  • 24 mensajes

Escrito 14 julio 2021 - 09:21

Que tal amigos, estoy implementando Task para los eventos onclick, donde ocupo mandar comandos a un servidor Indy, empecé a implementar de está forma con el botón aceptar del login de está manera:


delphi
  1. procedure TComanda.btAceptarClick(Sender: TObject);
  2. Var
  3. R :String;
  4. T :ITask;
  5. begin
  6. ProcesoBegin;
  7. T := TTask.Create(procedure
  8. begin
  9. DeshabilitaBtn;
  10. if (edUsuario.Text <> '') and (edPass.Text <> '') then
  11. begin
  12. if IdTCPClient1.Connected then
  13. begin
  14. try
  15. IdTCPClient1.SendCmd('salir ' + IDCliente);
  16. finally
  17. IdTCPClient1.Disconnect;
  18. end;
  19. end;
  20. R := Conectar;
  21. if R <> '' then
  22. begin
  23. try
  24. TThread.Synchronize(nil, procedure
  25. begin
  26. JUser := TJSONObject.ParseUtf8(R) as TJSONObject;
  27. if (JUser.S['valido'] = '1') then
  28. begin
  29. ContL := 0;
  30. if BCon = 0 then
  31. begin
  32. tbPrincipal.SetActiveTabWithTransition(tbCC, TTabTransition.Slide);
  33. CC;
  34. lbUser.Text := JUser.S['nombreLargo'];
  35. end
  36. else if BCon = 1 then
  37. begin
  38. CargaMesas;
  39. tbPrincipal.SetActiveTabWithTransition(tbMesas, TTabTransition.Slide);
  40. lbUser.Text := JUser.S['nombreLargo'];
  41. end
  42. else if BCon = 2 then
  43. begin
  44. tbPrincipal.SetActiveTabWithTransition(tbDetalle, TTabTransition.Slide);
  45. lbUser.Text := JUser.S['nombreLargo'];
  46. end;
  47. end
  48. else
  49. begin
  50. ShowMessage('Datos incorrectos');
  51. ProcesoEnd;
  52. edUsuario.SetFocus;
  53. end;
  54. ProcesoEnd;
  55. end);
  56. except on e :exception do
  57. ShowMessage('Ha ocurrido un error : ' + e.ClassName);
  58. end;
  59. end;
  60. end
  61. else
  62. begin
  63. ShowMessage('Es necesario ingresar usuario y contraseña para continuar');
  64. Inc(ContL);
  65. if ContL > 3 then
  66. begin
  67. ShowMessage('Se cerrará la aplicación debido a 3 intentos incorrectos');
  68. btExitClick(btExit);
  69. end;
  70. end;
  71. end);
  72. T.Start;
  73. DeshabilitaBtn;

Al implementarlo de está manera todo ok, mi problema viene después al tratar de usar otro task en otro evento onclick, deja de funcionar el evento onclick del login, se queda congelado, alguien le ha pasado?, cabe resaltar que en windows funciona bien, en android es donde pasa todo esto; muchas gracias de antemano por la ayuda.
Este es el segundo evento onclick donde trato de poner el segundo task.


delphi
  1. procedure TComanda.BotonClickCC(Sender: TObject);
  2. var
  3. TCC :ITask;
  4. begin
  5. ProcesoBegin;
  6. tbPrincipal.SetActiveTabWithTransition(tbMesas, TTabTransition.Slide);
  7. NR := 0;
  8. Tiempo := '1';
  9. Comensal := '1';
  10. lbCC.Text := (Sender as TButton).Text;
  11. CenCon := (Sender as TButton).Text;
  12. Caja := (Sender As TButton).TagString;
  13. TCC := TTask.Create(procedure
  14. begin
  15. if Not ValidarConexion then
  16. exit;
  17. BCon := 1;
  18. end);
  19. TThread.Synchronize(nil, procedure
  20. begin
  21. CargaMesas;
  22. ProcesoEnd;
  23. end);
  24. TCC.Start;
  25. end;


  • 0




IP.Board spam blocked by CleanTalk.