procedure TLocationForm.btnSendClick(Sender: TObject);
begin
with dmMyLocation do
begin
if not fgActivityDialog.IsShown then
begin
fgActivityDialog.Message := 'Please, Wait';
fgActivityDialog.Show;
FActivityDialogThread := TThread.CreateAnonymousThread(procedure
begin
Sleep(1000);
if TThread.CheckTerminated then
Exit;
TThread.Synchronize(nil, procedure
begin
fgActivityDialog.Message := 'Sending data...';
end);
try
qInsert.SQL.Clear;
qInsert.SQL.Add('INSERT INTO mabsensilokasi(');
qInsert.SQL.Add('idlokasi,');
qInsert.SQL.Add('tgllokasi,');
qInsert.SQL.Add('latx,');
qInsert.SQL.Add('longx,');
qInsert.SQL.Add('latlongx,');
qInsert.SQL.Add('namalokasi) ');
qInsert.SQL.Add('VALUES(');
qInsert.SQL.Add(':idlokasi,');
qInsert.SQL.Add(':tgllokasi,');
qInsert.SQL.Add(':latx,');
qInsert.SQL.Add(':longx,');
qInsert.SQL.Add(':latlongx,');
qInsert.SQL.Add(':namalokasi)');
qInsert.Prepare;
qInsert.Params[0].AsInteger := 0;
qInsert.Params[1].AsDateTime := Now;
qInsert.Params[2].AsFloat := strToFloat(ENUSLat);
qInsert.Params[3].AsFloat := strToFloat(ENUSLong);
qInsert.Params[4].AsString := ENUSLat+':'+ENUSLong;
qInsert.Params[5].AsString := edtNamaLokasi.Text;
try
UniConnection1.Connect;
qInsert.ExecSQL;
TThread.Synchronize(nil, procedure
begin
ShowMessage('Record was saved into MySQL Server DB...'); //showup windows of dialog when data was save succesfully into db mysql server
end);
except
on e:exception do
begin
TThread.Synchronize(nil, procedure
begin
ShowMessage(e.Message);
UniConnection1.Disconnect;
end);
end;//exception
end;//try
//fgActivityDialog.ExecuteAction(btnSend);
Sleep(1000);
if TThread.CheckTerminated then
Exit;
TThread.Synchronize(nil, procedure
begin
fgActivityDialog.Message := 'Finish';
end);
Sleep(500);
if TThread.CheckTerminated then
Exit;
finally
if not TThread.CheckTerminated then
TThread.Synchronize(nil, procedure
begin
fgActivityDialog.Hide;
end);
end;//try
end);//FActivityDialogThread
FActivityDialogThread.FreeOnTerminate := False;
FActivityDialogThread.Start;
end;//if
end;//endDM
end;//endProc
I have changed your code a little bit. To make some kind of separation.