2
In Delphi 10.2, I have a Form A that has a Ttask "Task-A" that fires a Storedprocedure in the Oracle bank with Firedac. Storedprocedure updates a table of results that will be used by a form B which has a graph. I would like to call Form B inside a "Task-B" Ttask, which calls Forms B with the graph and can return to Form A, while the graph is updating in the other Forms B ! I used the following command to open Form B inside a Ttask , BUT FROZE THE APPLICATION ! Thanks for the personal help !
procedure TFormA.SpeedButtonChamaGrafico(Sender: TObject);
var
Tarefaproc, Tarefagrafico : iTask;
begin
// Chamada da StoredProcedure dentro da TTask ==> funciona corretamente !!
Tarefaproc := TTask.Create( procedure ()
begin
with FDStoredProc1 do
begin
Prepare;
Params[0].Value := StrToInt(EditCenario.Text);
Execproc;
end;
end);
Tarefaproc.Start;
// Logo em seguida, chamada do FormB dentro de outra TTASK ==> DÁ ERRO, congela a aplicação !!
Tarefagrafico := TTask.Create( procedure ()
begin
try
Application.CreateForm(TformB,FormB);
FormB.ShowModal;
finally
Freeandnil(formB);
end;
end);
Tarefagrafico.Start;
I believe the freeze is given
ShowModal
, note that the task cannot be terminated automatically, in which case it would be stopped atShowModal
disconnected from the main application. Test theShow
and tell us the result.– Junior Moreira
@Junior, I will make this modification along with the proposal by Kelver, below. Thank you.
– JRG
@Junior, I tested the show . When I use Formb.show the Forms appears and scarf on the screen , in a blink ! As the Form is the main application, open with showmodal , from it I call the Formb with another showmodal thus becoming the focus and not allowing to return to the Form. Is there any other way to allow you to switch focus between two open forms ? I appreciate your help.
– JRG
The control is done only by
Modal
the problem is that theThread
is unlinking the "B" from the main application.– Junior Moreira
@Junior, I found the mistake! It was obvious , but my lack of experience did not allow us to immediately see that the call from Formb.Show was inside a Try.. Finally , as the last Finally command was Freeandnil(formB), this obviously closed and ended the form right after the Show. I took it and it worked ! Thank you so much for your support and tips !
– JRG