Recent

Author Topic: [SOLVED] Speeding up the creation of forms at run-time  (Read 1256 times)

EganSolo

  • Sr. Member
  • ****
  • Posts: 334
[SOLVED] Speeding up the creation of forms at run-time
« on: May 26, 2025, 09:19:57 am »
I've got a heavy, data-dependent form that I create at runtime. I want to delay the form's display until all components have been loaded. I thought a form had a Begin/EndUpdate pair, but they don't exist. Suggestions?
 
« Last Edit: June 04, 2025, 07:49:18 am by EganSolo »

cdbc

  • Hero Member
  • *****
  • Posts: 2253
    • http://www.cdbc.dk
Re: Speeding up the creation of forms at run-time
« Reply #1 on: May 26, 2025, 09:30:32 am »
Hi
Hmmm, have your model gather the data and then signal the presenter to show the form, when ready...
...BUT if you have all your business-logic entangled in the form, it becomes a whole lot trickier, 'cuz in my experience, the LCL doesn't respond too well to delays in the creation and showing mechanism...  %)
Good luck  ;D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Thaddy

  • Hero Member
  • *****
  • Posts: 17414
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: Speeding up the creation of forms at run-time
« Reply #2 on: May 26, 2025, 09:47:55 am »
You can override Tform.AfterConstruction.
Don't forget to call inherited first.
This guarantees that any control on the form and of course the form itself is fully initialized before the form is shown.
In AfterConstruction you can handle any additional setup if required.
« Last Edit: May 26, 2025, 09:52:44 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

jamie

  • Hero Member
  • *****
  • Posts: 6991
Re: Speeding up the creation of forms at run-time
« Reply #3 on: May 26, 2025, 12:41:39 pm »
I would just simply keep the form invisible after creation until the last component has loaded its data meanwhile the spinning cursor can be on the screen indicating loading.
The only true wisdom is knowing you know nothing

Handoko

  • Hero Member
  • *****
  • Posts: 5458
  • My goal: build my own game engine using Lazarus
Re: Speeding up the creation of forms at run-time
« Reply #4 on: May 26, 2025, 08:18:49 pm »
Maybe not what you want, I show a progress bar during the data preparation, you can download and try the code here:
https://forum.lazarus.freepascal.org/index.php/topic,50989.msg374461.html#msg374461

CharlyTango

  • Full Member
  • ***
  • Posts: 142
Re: Speeding up the creation of forms at run-time
« Reply #5 on: May 27, 2025, 10:41:54 am »
I've got a heavy, data-dependent form that I create at runtime. I want to delay the form's display until all components have been loaded. I thought a form had a Begin/EndUpdate pair, but they don't exist. Suggestions?
 

I don't know from which source you load the forms data. If it is from a SQL database some kind of data preparation in the SQL Server helps to speed up.
Sometimes i even used an additional table which ist prepared by the SQL Server to improve speed.

To leave the user uninformed what actually happens ist bad style.
Especially when research has shown that the temporal perception of users can be positively influenced by an animated object. That's why the approach with a progress bar is the right direction.  If you can't estimate the time, then use any animated GIF that you display in the meantime.
Lazarus stable, Win32/64

Thaddy

  • Hero Member
  • *****
  • Posts: 17414
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: Speeding up the creation of forms at run-time
« Reply #6 on: May 27, 2025, 10:49:05 am »
You could also just change the cursor.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

cdbc

  • Hero Member
  • *****
  • Posts: 2253
    • http://www.cdbc.dk
Re: Speeding up the creation of forms at run-time
« Reply #7 on: May 27, 2025, 10:59:46 am »
Hi
Hmmm, to recap...:
- In the TForm1.AfterConstruction();
-- change the cursor to 'Busy' or start some kind of animation
-- I would personally start a 'Data-Preparation-Thread' to load data while the
    form is showing, depending on component-count it takes some msecs
-- in the 'FormShow' handler, I'd assign the loaded data to components,
    possibly in stages when they're ready
-- finally I'd change the cursor back to 'Idle'
Just my 2 cents worth...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

EganSolo

  • Sr. Member
  • ****
  • Posts: 334
Re: Speeding up the creation of forms at run-time
« Reply #8 on: May 30, 2025, 02:05:51 am »
Thanks, Guys! Your input is great! I love the help!

Here's the process I'm currently following:
  • I create the form.
  • I give it a list of objects that specify a frame to instantiate and its left, top, width and height positions. There could be up to twenty such frames. These frames contain between 5 to 25 controls.

My issue is that the form shows first, and we see the frames being created.

Based on your comments, I should:
  • Create the form.
  • Hide it.
  • Set the cursor to hourglass.
  • Optionally show a progress bar.
  • Create the frames.
  • Reset the cursor and show the form.

I'll give that a try and report back.

EganSolo

  • Sr. Member
  • ****
  • Posts: 334
Re: Speeding up the creation of forms at run-time
« Reply #9 on: June 04, 2025, 07:49:02 am »
That worked.
It was a bit counterintuitive to invoke hide in the constructor; I had assumed frames were created hidden and should have checked. Still, it worked!

Again, I appreciate all the help I received. Thank you very much.

etrusco

  • New Member
  • *
  • Posts: 17
Re: [SOLVED] Speeding up the creation of forms at run-time
« Reply #10 on: June 12, 2025, 05:28:25 pm »
It's indeed created hidden, unless you use Application.CreateForm to instantiate it and the FormStyle is fsSplash.

 

TinyPortal © 2005-2018