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:
Código Delphi
[-]
procedure TComanda.btAceptarClick(Sender: TObject);
Var
R :String;
T :ITask;
begin
ProcesoBegin;
T := TTask.Create(procedure
begin
DeshabilitaBtn;
if (edUsuario.Text <> '') and (edPass.Text <> '') then
begin
if IdTCPClient1.Connected then
begin
try
IdTCPClient1.SendCmd('salir ' + IDCliente);
finally
IdTCPClient1.Disconnect;
end;
end;
R := Conectar;
if R <> '' then
begin
try
TThread.Synchronize(nil, procedure
begin
JUser := TJSONObject.ParseUtf8(R) as TJSONObject;
if (JUser.S['valido'] = '1') then
begin
ContL := 0;
if BCon = 0 then
begin
tbPrincipal.SetActiveTabWithTransition(tbCC, TTabTransition.Slide);
CC;
lbUser.Text := JUser.S['nombreLargo'];
end
else if BCon = 1 then
begin
CargaMesas;
tbPrincipal.SetActiveTabWithTransition(tbMesas, TTabTransition.Slide);
lbUser.Text := JUser.S['nombreLargo'];
end
else if BCon = 2 then
begin
tbPrincipal.SetActiveTabWithTransition(tbDetalle, TTabTransition.Slide);
lbUser.Text := JUser.S['nombreLargo'];
end;
end
else
begin
ShowMessage('Datos incorrectos');
ProcesoEnd;
edUsuario.SetFocus;
end;
ProcesoEnd;
end);
except on e :exception do
ShowMessage('Ha ocurrido un error : ' + e.ClassName);
end;
end;
end
else
begin
ShowMessage('Es necesario ingresar usuario y contraseña para continuar');
Inc(ContL);
if ContL > 3 then
begin
ShowMessage('Se cerrará la aplicación debido a 3 intentos incorrectos');
btExitClick(btExit);
end;
end;
end);
T.Start;
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
Código Delphi
[-]
procedure TComanda.BotonClickCC(Sender: TObject);
var
TCC :ITask;
begin
ProcesoBegin;
tbPrincipal.SetActiveTabWithTransition(tbMesas, TTabTransition.Slide);
NR := 0;
Tiempo := '1';
Comensal := '1';
lbCC.Text := (Sender as TButton).Text;
CenCon := (Sender as TButton).Text;
Caja := (Sender As TButton).TagString;
TCC := TTask.Create(procedure
begin
if Not ValidarConexion then
exit;
BCon := 1;
end);
TThread.Synchronize(nil, procedure
begin
CargaMesas;
ProcesoEnd;
end);
TCC.Start;
end;