I have an app that transmits the image to a remote server. It is working fine .
But if the user touches the screen it crashes the app and returns ” not working ” or “app is not responding .”
I wanted:
1) temporarily lock the screen.
2) I was using Application.ProcessMessages ; for the app not stop. Is corret ?
var
lista:tlista;
proxy: TServerMethods2Client;
i:integer;
trans: TDBXTransaction;
Myvisita:TvisitaDs;
MyEventos:TEve_ClIDS;
Protoco:Tprotocolo;
Ini: TIniFile;
MyAnexos : TAnexosDs;
oArquivoJSON: TJSONArray;
begin
try
Datasnap.close;
with Datasnap do
begin
Params.Values[‘HostName’] := Edit2.Text;
Params.Values[‘Port’] := ‘211’;
end;
Datasnap.Connected:=true;
Ini :=TIniFile.Create(TPath.Combine(GetHomePath,’maitech.ini’));
Ini.WriteString(‘Conexao’,’Path’,Edit2.Text);
Ini.Free;
except
on e:exception do
begin
mensagem(‘Sem conexão com o servidor remoto’,0);
exit;
end;
end;
AniIndicator1.Enabled:=true;
AniIndicator1.Visible:=true;
{ testa a conexao }
try
Datasnap.Open;
proxy := nil;
proxy := TServerMethods2Client.Create(Datasnap.DBXConnection);
except
on e: Exception do
begin
ShowMessage(‘Sem conexão com o servidor central’ + #13 + ‘Evento:’ + e.Message);
exit;
end;
end;
lista:=Tlista.Create;
lista := lista.JSON_To_Lista(proxy.Data_to_Mobile(FormPrincipal.usuario_id,’key’));
WITH Basedados DO
BEGIN
ProgressBar1.Value:=0;
ProgressBar1.Max:=100;
{ transfere os arquivois para o servidir }
begin
MyAnexos := TAnexosDs.Create;
queryQ.Close;
queryQ.CommandText := ‘Select * from anexos where REPLICACAO_EFETUADA=”NÃO” ‘;
queryQ.Open;
ProgressBar1.Value:=0;
ProgressBar1.Max:=QueryQ.RecordCount;
queryQ.First;
while NOT queryQ.Eof do
begin
label1.text:=’Transmitindo dados do anexo [‘ + IntToStr(queryQ.RecNo) + ‘]’;
try
MyAnexos.LoadData(MyAnexos,QueryQ);
Protoco := JSONToProtocolo(proxy.Receive_Anexo(MyAnexos.AnexosDs_To_JSON(MyAnexos)));
SetProtocolo(‘ANEXOS’, MyAnexos.id, Protoco.id);
// Aqui chama a funcão de UpLoad ||
//*****************************************//
// HERE CALL FUNCTION TO UPLOAD THE FILE IMAGE ,
//*****************************************//
oArquivoJSON := fArquivoParaJSON(TPath.Combine(ImgDownload,queryQ.FieldByName(‘url’).AsString));
Application.ProcessMessages;
label1.Text:=’Inicio do processo’;
proxy.pUploadArquivo(oArquivoJSON,queryQ.FieldByName(‘url’).AsString);
ProgressBar1.VALUE:=QueryQ.RecNo;
except
on e: Exception do
begin
end;
end;
MyAnexos.LoadData(MyAnexos, queryQ);
Protoco := JSONToProtocolo(proxy.Receive_Anexo(MyAnexos.AnexosDs_To_JSON(MyAnexos)));
{ faz o update do protocolo no objeto }
try
SetProtocolo(‘ANEXOS’, MyAnexos.id, Protoco.id);
except
on e:exception do
begin
end;
end;
label1.text:=’Anexo registrados, preparando para transfereir’;
queryQ.Next;
end;
end;
Datasnap.Close;
proxy.Free;
mensagem(‘Envio realizado com sucesso’,0);
ModalResult:=mrOk;
close;
//
end;
end;
Upload Image
function TFormSincronizacao.fArquivoParaJSON(pDirArquivo: string): TJSONArray;
var
arq:TJSONArray;
AFileStream: TFileStream;
begin
AFileStream := TFileStream.Create(pDirArquivo, fmOpenRead);
label1.Text:=’Convertendo imagem ‘;
arq := TDBXJSONTools.StreamToJSON(AFileStream, 0, AFileStream.Size);
Result:=arq;
end;