2

I'm using TScrollBox to make custom list contains many controls (Tlabels,Timages,Tshapes)

the problem is when i use TPanels as a container for each Item the list getting slow and flickery after adding about 100 items.

i'm looking for an alternative to TPanel based on TGraphicControl to improve the performance

Somebody
  • 703
  • 1
  • 7
  • 23
  • 2
    You can make a `TGraphicControl` descendant that will use some sort of virtual objects (like layers). You would have a list of virtual object definitions (object size, position, text, shape,...) and you would render to an offscreen bitmap by those definitons whenever any of the definitons changes. The rest would be about blitting the offscreen bitmap. – TLama Jan 16 '15 at 00:54
  • 3
    Nothing based on TGraphicControl can parent other controls. – Sertac Akyuz Jan 16 '15 at 01:03
  • @TLama that's a good idea but i'm using TScrollbox with panels and controls instead of TListView to be able to handle events on each control that is not possible using this method – Somebody Jan 16 '15 at 01:04
  • 1
    Perhaps you could use a TFrame instead of a TScrollBox. I have some TFrames containing close to 1000 controls, and the TFrames scroll well. I divide the TFrame into sections using TGroupBoxes. – Ron Maupin Jan 16 '15 at 01:09
  • What you've listed are graphic controls (`TLabel`, `TImage`, `TShape`) and those you could render. And you could handle events (look e.g. what Andreas made with *virtual* [`triangles`](http://stackoverflow.com/a/7224075/960757)). – TLama Jan 16 '15 at 01:11
  • @RonMaupin i think you mean using TFrame instead of TPanels not TScrollbox ? i tried it, almost the same result – Somebody Jan 16 '15 at 01:24
  • @Karim Ezzat I mean using a TFrame instead of a TScrollBox. – Ron Maupin Jan 16 '15 at 01:29
  • You would hit a practical limit eventually. The better approach IMO would be to create only the controls that would be visible and free the ones that go out of range. Might require quite a redesign though. – Sertac Akyuz Jan 16 '15 at 01:40
  • @RonMaupin i tried it now unfortunately both TScrollbox and TFrame the same result – Somebody Jan 16 '15 at 01:46
  • @SertacAkyuz the controls are frequently updating i can't free any of them – Somebody Jan 16 '15 at 01:49
  • 2
    Why do you need containers? – David Heffernan Jan 16 '15 at 07:26
  • @DavidHeffernan i thought of making it without containers but it will be hard to align and resort – Somebody Jan 16 '15 at 10:15
  • It sounds like you want to have your cake and eat it. Stuffing everthing inside panels is just asking for flicker. It's time for you to step up and do that thing that you say will be hard. – David Heffernan Jan 16 '15 at 10:28
  • @DavidHeffernan not exactly :) , i though its possible to make TGraphicControl Panel to use it instead of TWinControl. but it seem not possible – Somebody Jan 16 '15 at 11:23
  • @DavidHeffernan ok , i made it without containers (only TLabels and TImages) , its little faster but when i add more items it get the same flicker on scrolling ... wondering how controls such TListBox can handle thousands of items without this issue – Somebody Jan 25 '15 at 18:57
  • @TLama i did ur idea with TPaintbox and offscreen bitmaps as u mentioned , its running great and now i can add over 1000 item smoothly. kindly place your comment as an answer thanks – Somebody Jan 27 '15 at 04:01

2 Answers2

1

You can also turn Form.DoubleBuffered := True to prevent flickery

0

instead of using controls in panel container , i used TPaintBox for each row to draw using canvas as suggested

Somebody
  • 703
  • 1
  • 7
  • 23