When i call a function and it "runs" (Can be take up to 3 seconds - refresh function getting data from api server) I would like to show a loadingform as an Ajax Loading Indicator as an overlay above the main form.
My previous attempts have all failed. I had tried to change the Create the LoadingForm that it is directly shown after the Main created. Then I tried LoadingForm.Show/Showmodal. In the modal sequence stops and only continues when I close the form and show the window does not close despite .
I also had the situation that the form was opened but the gif wasnt showing, the place where it should be was just white and stayed white - no image no animation
Any idear?
The code below uses a thread to mimic a long time running block in its
Execute
method and theOnProgress
"callback" to notify the form the percent done has changed.It's a very minimal example but it can show you one of the right directions in my opinion.
Notice that no error checking nor exception handling are currently performed.
Unit1.pas
the main form and the thread classUnit1.dfm
Unit2.pas
the progress dialogUnit2.dfm
Referring to the comment which states that the long time running operations need to access a grid in the main form, in order to avoid to block the VCL thread on that object:
ShowModal
returns.myRunProgress
or in themyRunTerminate
methodFor different use cases a mixed approach could also make sense (pass the copy in the constructor/update the grid in a thread's syncronized block) if your routine doesn't take in account the already changed data: choose the method which best suits your needs.
If another external thread updates the grid, a
thread1
could read the data then fill a form's private queue - say aTThreadList
or another collection in aTCriticalSection
block - and notify athread2
to perform a job on the queue but I hope this is probably not needed to have your job done.