Recent

Author Topic: My app doesn't run sequential  (Read 169 times)

ChristianundCo

  • New member
  • *
  • Posts: 6
My app doesn't run sequential
« on: October 25, 2019, 10:19:59 am »
Hi,

I have a problem with my windows app. It doesn't work sequential.

Example:
There is a "Memo" - element and in there is a result from a earlier calculation.
Now another procedure is called.
At first I want to put a 'please wait' into the memo

Code: Pascal  [Select]
  1. procedure TForm1.ListBox1DblClick(Sender: TObject);    
  2.  var
  3. newresult:String;
  4. begin
  5.  
  6.        Form1.Memo1.Text:='Please wait';    
  7.  
  8.  
  9. ...// a lot of calculation User has to wait some seconds and at the end there is a new result
  10.  
  11. Form1.Memo1.Text:= newresult;
  12. end;
  13.  

But when I run the app and call the procedure it doesn't insert the 'please wait' into the memo before big calculation starts.
It just change the Memo1 when the newresult is there and the user saw the old result in memo during the calcalation.
It works so:
1. precedure is called
2. calculation
3. put 'Please wait' in Memo
4. put new result in Memo

That's wrong! :(




If I insert a "ShowMessage ('Hello');" into my code it works well.

Code: Pascal  [Select]
  1. procedure TForm1.ListBox1DblClick(Sender: TObject);    
  2.  var
  3. newresult:String;
  4. begin
  5.  
  6.        Form1.Memo1.Text:='Please wait';    
  7.      ShowMessage('Hello');
  8.  
  9. ...// a lot of calculation User has to wait some seconds and at the end there is a new result
  10.  
  11. Form1.Memo1.Text:= newresult;
  12. end;
  13.  

That works as it should
1. precedure is called
2. put 'Please wait' in Memo
3. ShowMessage
4. calculation
5. put new result in Memo

How can I solve that without to use a "ShowMessage" ?
« Last Edit: October 25, 2019, 10:22:40 am by ChristianundCo »

MarkMLl

  • Sr. Member
  • ****
  • Posts: 302
Re: My app doesn't run sequential
« Reply #1 on: October 25, 2019, 10:25:31 am »
Try calling  Application.ProcessMessages;  immediately after you've put the text in the memo.

It works to generally synchronise the GUI with the actual program, but don't overuse it (e.g. every few uSec in the middle of a calculation loop) since it can have a substantial performance hit.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

ChristianundCo

  • New member
  • *
  • Posts: 6
Re: My app doesn't run sequential
« Reply #2 on: October 25, 2019, 10:46:33 am »
Thanks a lot!

That works!