Problem showing transient text in a Tedit lazarus / 21-General ---------------------------------------------------------------------- uart · 2022-04-13 11:51 I've got a program with a really simple structure. It's just a simple form (Form1) with a few combo boxes, check boxes and edits, which are used to set up some input parameters, and then a "Go" button to invoke some calculations using those parameters. The form (Form1) is in one unit (Unit1) and the computation engine (with no I/O) is another unit (Unit2). The code I'm interested in is just the calling of the computation engine and display of results. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var returnStr : string;...begin {read input params from combo boxes} CompEngine({input params}, returnStr);  // Can take up to 15 seconds edit1.Text:=returnStr;end;     The program works fine, and after the computation "edit1" displays the results that are passed back in var parameter "returnStr". The only problem I have is that, depending on the input parameters, the "CompEngine" can take anywhere from a few milliseconds up to about 15 seconds to complete. So I'd like it to display something like 'Thinking ...' while CompEngine is running. The following however doesn't work, the 'Thinking ...' part just doesn't seem to display. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var returnStr : string;...begin {read input params from combo boxes} edit1.Text:='Thinking ...'; CompEngine({input params}, returnStr);  // Can take up to 15 seconds edit1.Text:=returnStr;end;   So I'm guessing that it's optimised out of order or something, and the 'Thinking ...' part doesn't get written to edit1 until after the CompEngine completes (so you don't see it because it immediately get overwritten with the returnStr). Anyway, that's just a guess, but does anyone have a simple solution? ---------------------------------------------------------------------- Zvoni · 2022-04-13 11:55 Own Thread with Callback? EDIT: second codeblock Insert between Line 6 and 7 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i edit1.Refresh; ---------------------------------------------------------------------- uart · 2022-04-13 12:00 Quote from: Zvoni on April 13, 2022, 01:55:38 pmOwn Thread with Callback? Thanks Zvoni. The program is very simple and I don't make any explicit use of threads. I don't know if the compiler does that by default or anything, but I'm not using any threads. ---------------------------------------------------------------------- Zvoni · 2022-04-13 12:02 Quote from: uart on April 13, 2022, 02:00:59 pmQuote from: Zvoni on April 13, 2022, 01:55:38 pmOwn Thread with Callback? Thanks Zvoni. The program is very simple and I don't make any explicit of of threads. I don't know of the compiler does that by default or anything, but I'm not using any threads. See my Edit btw: Why use a Var-Parameter in a Procedure and not a Function-Result? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Function CompEngine({Input-Params}):String;Begin//DoSomething with ParamsResult :=SomeComputedResult;End;.. Beginedit1.Text:='Thinking...';edit1.Refre sh;edit1.Text:=CompEngine({input-params}); ---------------------------------------------------------------------- Sieben · 2022-04-13 12:06 You could try sth like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    procedure TForm1.Button1Click(Sender: TObject);   var returnStr : string;   ...   begin     Screen.BeginWaitCursor;     try       {read input params from combo boxes}       edit1.Text:='Thinking ...';       Application.ProcessMessages;       CompEngine({input params}, returnStr);  // Can take up to 15 seconds       edit1.Text:=returnStr;     finally       Screen.EndWaitCursor;     end;   end; ---------------------------------------------------------------------- uart · 2022-04-13 12:12 Quote from: Zvoni on April 13, 2022, 02:02:04 pmSee my Edit Thanks, that's just what I was looking for, something nice and simple. Quote btw: Why use a Var-Parameter in a Procedure and not a Function- Result? No reason in particular. That's just the way I've always preferred when returning non scalar results like strings or arrays. TBH It's probably based on certain restrictions on function return types dating back decades (turbo pascal 3) that are no longer relevant. ---------------------------------------------------------------------- Zvoni · 2022-04-13 12:12 urgghh...Sieben ProcessMessages is boo boo :-) a Simple Refresh to force the edit to repaint is enough ---------------------------------------------------------------------- Sieben · 2022-04-13 12:14 Might be sufficient on Windows, might not on Linux... ---------------------------------------------------------------------- Zvoni · 2022-04-13 12:17 Quote from: uart on April 13, 2022, 02:12:49 pmNo reason in particular. That's just the way I've always preferred when returning non scalar results like strings or arrays. TBH It's probably based on certain restrictions on function return types dating back decades (turbo pascal 3) that are no longer relevant. Ah, OK. I make it dependant. If i expect a single result, and the computation of that result can NOT throw any errors or exceptions, then i use a Function-Result If i expect 2 or more results back, then i use var/out-Parameters Independant if i expect 1 or more results back, if the computation of those results can go wrong, i always use a Function with var/out- Params for the Results, and the Function-Result itself for an Error- Code (in principle the way the Windows-API actually works in most cases) ---------------------------------------------------------------------- uart · 2022-04-13 12:40 Quote from: Zvoni on April 13, 2022, 02:17:11 pm if the computation of those results can go wrong, i always use a Function with var/out- Params for the Results, and the Function-Result itself for an Error- Code Yes that's how I prefer to handle that situation too. Often the return result is just boolean (error or no error) and the result(s) in var/out parameter(s). In this CompEngine the return string gets hacked around quite a lot in the procedure before the final return string is assembled. So if it was a function I'd probably still have it as a local variable while it's being manipulated and assign it to the return result right at the end anyway. It might look a tiny bit neater as a function but overall it wouldn't make much difference.