Jump to content
#ifdef

TControlList — need help!

Recommended Posts

Posted (edited)

I added dynamic (variable) row heights to TControlList and it works:

 

TControlList.thumb.gif.b183ef1a05e3b24c9da52bd5147c8375.gif

 

But when resizing the form, the TControlList is terribly slow.

 

@Serge_G I know you are a guru in this list. Please tell me how this can be fixed?

 

Project1.zip

Edited by #ifdef

Share this post


Link to post

The delay is due to the fact that whenever the users moves the mouse during the resizing the getCaption is executed. It costs time to calculate the required space for every item.

 

Share this post


Link to post

It's impossible to speed things up? 😞

Share this post


Link to post

A scroll bar that is based on # of rows instead of height and only using enough labels to fill the visible area - swapping/drawing content, as necessary. The drawback is jumpy scrolling instead of smooth due to row at a time vs line at a time, but it is orders of magnitude faster.  

 

A lot more work to do it with a ControlList but most grids that support variable row height will do all it for you. 

Share this post


Link to post

Thanks for the guru, but actually I am on holidays (let say I prefer this term  that a low activity scheme due to retirement 😉

Sure, I will have a look to your project. TControlList variable row heights was in my lengthy to-do list when retired but, as I really prefer FMX TListview this to-do item was in the bottom 10.  

  • Like 1

Share this post


Link to post
Posted (edited)

So, I have a look and test with 11.3 and 12.1 (entreprise) and no slow comportment found. So, for me, you got it.🙌

You said you use which version, community ok but last one (which is now a 11.2 or 11.3 version don't remember exactly ) ?

As I see in your code, the key is the  TControlList.FHeights I never found (for my discharge, I just deep dive in this component at the first occurrence and never run back in it)

Edited by Serge_G

Share this post


Link to post
1 hour ago, Serge_G said:

So, I have a look and test with 11.3 and 12.1 (entreprise) and no slow comportment found. So, for me, you got it.🙌

You said you use which version, community ok but last one (which is now a 11.2 or 11.3 version don't remember exactly ) ?

As I see in your code, the key is the  TControlList.FHeights I never found (for my discharge, I just deep dive in this component at the first occurrence and never run back in it)

Thank you for your kind words, but no, I don’t think I succeeded, that's why I decided to contact you personally 😞

 

I have 11.3 CE (28.0.48361.3236), you are right, but it probably should look and work the same on 12.1: the problem occurs when the form changes size.

 

What about the "FHeights" - it's just a temporary storage of row sizes (like a cache or something).

Share this post


Link to post

0.gif.757763b5430ad09b96883b33e1587591.gif

 

You can try changing "100" to "1000" and change the size of the form after compilation

Share this post


Link to post

Making a Windows API call for every cell to get the text height will be slow period. The call is required since the text needs to be re-flowed when the width changes. It does all cells to get a new total height.

 

As I mentioned for speed you need a different approach that doesn't need to calculate total height.  

Share this post


Link to post

 

You could try something like this. Add a new private field to the form 

   fPrevWidth: integer;

 

 

procedure TForm1.FormResize(Sender: TObject);
begin
  if (Abs(fPrevWidth-width)>50) or (GetAsyncKeyState(VK_LBUTTON) and $8000 = 0) then
  begin
    getCaption;
    fPrevWidth:=Width;
  end;
end;

 

 

Share this post


Link to post

@#ifdef Well i can't compile your project nor i have an idea what TControlList is, yet from your last post i can deduce the problem.

Se, same behavior is visible with Windows Notepad, you can try it, open a big text file something around few MBs and make sure that Word Wrap is enabled, and see for your self, same behavior, disabling the Word Wrap will make it fast like it was few lines.

Calculating the height of paragraph is demanding process, because it only possible with a font and a width, after that rendering will happen again with the font applying device context parameters, so it might be doable but not like that it must involve caching.
The only components i know of that do this right (or lets say fast) is the controls from Delphi HTML components.


Yet, there is may be a workaround in your case, which is switching to virtual drawing, and rendering only what should be visible while emulating the scrollbar position at side, in other words you need to switch to owner draw and draw text manually what is enough to fill the control.

Share this post


Link to post
3 minutes ago, Lajos Juhász said:

So these are TMemo(s) in the list ! not even simple and plain text lines in a list box.

 

Anyway, same recommendation as for single Memo or ListBox, switch to owner drawing, then limit what you are using/rendering/showing to the visible ones, while simulate/emulate a scroll bar on the side, or it might support its own scrollbar, who knows.

Share this post


Link to post
11 minutes ago, Kas Ob. said:

Se, same behavior is visible with Windows Notepad, you can try it, open a big text file something around few MBs and make sure that Word Wrap is enabled, and see for your self, same behavior, disabling the Word Wrap will make it fast like it was few lines.

I know but... in Notepad++ everything is ok 🥲

Share this post


Link to post
1 minute ago, Kas Ob. said:

So these are TMemo(s) in the list ! not even simple and plain text lines in a list box.

 

Anyway, same recommendation as for single Memo or ListBox, switch to owner drawing, then limit what you are using/rendering/showing to the visible ones, while simulate/emulate a scroll bar on the side, or it might support its own scrollbar, who knows.

Nope. TControlList if for TGraphicControl only:

 

image.thumb.png.6b74643b961fcae172065d21ffeeb4aa.png

Share this post


Link to post
12 minutes ago, #ifdef said:

I know but... in Notepad++ everything is ok 🥲

It is owner drawn in full.

9 minutes ago, #ifdef said:

Nope. TControlList if for TGraphicControl only:

Well i said i can't compile your project, and if all of these text segments are ... What ? (i don't care)

TLable or TMemo, then use 50-80 and just update their content simulating hundreds or thousands, instead of creating hundreds, update their contents based on the scroll bar.

You could also try to create the needed amount and try to clear the non visible and fill the few visible when resizing, i am throwing ideas here and hope might help.

Share this post


Link to post

By the way Notepad++ with 14mb text file with longs lines, very fast without Word Wrap, does stutter on resizing with Word Wrap enabled.

Share this post


Link to post
1 hour ago, Kas Ob. said:

By the way Notepad++ with 14mb text file with longs lines, very fast without Word Wrap, does stutter on resizing with Word Wrap enabled.

You can try Ultra Edit. It works well with big files.

Share this post


Link to post

Sorry, I don't need a text editor, I just need to somehow speed up the rendering of text with word splitting and that's it :classic_smile:

Share this post


Link to post

Do you need to be able to edit/use the textblocks or is it just for display?

word splitting = word wrap?

Share this post


Link to post
Posted (edited)
3 hours ago, Die Holländer said:

Do you need to be able to edit/use the textblocks or is it just for display?

No, I don't (anyway, TControlList is for TGraphicControl only).

 

 

3 hours ago, Die Holländer said:

word splitting = word wrap?

Yes.

Edited by #ifdef

Share this post


Link to post
On 6/27/2024 at 11:49 AM, #ifdef said:

I added dynamic (variable) row heights to TControlList and it works:

 

TControlList.thumb.gif.b183ef1a05e3b24c9da52bd5147c8375.gif

 

But when resizing the form, the TControlList is terribly slow.

 

@Serge_G I know you are a guru in this list. Please tell me how this can be fixed?

 

Project1.zip

 

Just out of interest, what tool do you use to create GIF's like this?

 

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×