Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 17 of 17 total
Thread Creating BasicPanels - Benchmarks
Sat, Apr 7 2018 11:44 AMPermanent Link

Mark Brooks

Slikware

Avatar

Uli Becker wrote:

>>Sure. I posted the test application with sources here:

Great - many thanks Uli
Sat, Apr 7 2018 11:54 AMPermanent Link

Mark Brooks

Slikware

Avatar

Uli Becker wrote:

>>That's why I use emtpy BasicPanels. The content is created later depending on the scroll position.

Hey Uli, if you are using the OnScroll event of the parent panel in order to populate the child panels that are visible, how do you work out which ones to populate i.e. which are now visible?
Sun, Apr 8 2018 3:52 AMPermanent Link

Uli Becker

Hi Mark,

> Hey Uli, if you are using the OnScroll event of the parent panel in order to populate the child panels that are visible, how do you work out which ones to populate i.e. which are now visible?

I'm just at the beginning: that's why my code may be unefficient. But
here is what I'm doing:

----------------------------------

procedure TForm2.ScrollBoxScroll(Sender: TObject);
var
   i, AMin, AMax: integer;
   TempAlbumItem : TAlbumItem;
begin
   AMin := (ScrollBox.ScrollTop div DEFAULT_HEIGHT) * 2;
   AMax := AMin + (VISIBLE_ROWS * COLUMNS) +1;
   if AMax > Albums.RowCount-1 then
      AMax := Albums.RowCount-1 ;

   Albums.MoveTo(AMin + 1);

   ScrollBox.BeginUpdate;
   try
      for i := AMin to AMax do
      begin
         if ScrollBox.Controls[i].Tag = 0 then
         begin
            TempAlbumItem :=
TAlbumItem.Create(TBasicPanel(ScrollBox.Controls[i]));
            with TempAlbumItem do
            begin
               with Layout do
               begin
                  Position := lpTopLeft;
                  Stretch := lsBottomRight;
               end;
               AlbumName := Albums.Columns['Name'].asString;
               AlbumArtists := Albums.Columns['Artists'].asString;
               AlbumURL := Albums.Columns['ImageURL_Medium'].asString;
            end;
            ScrollBox.Controls[i].Tag := 1;
            ScrollBox.Controls[i].Animations.Opacity.Duration := 200;
            ScrollBox.Controls[i].Animations.Opacity.Style := asLinear;
            ScrollBox.Controls[i].Opacity := 100;
         end;
         Albums.Next;
      end;
   finally
      ScrollBox.EndUpdate;
   end;
end;

----------------------------------------

TAlbumItem is a custom component derived from a TBasicPanel. To avoid
duplicate actions I use the tag-property of the panels.

I uploaded a small sample here:

http://beckersoft-online.de:8070/myspotify/virtual.html

After loading the dataset 200 panels are created, but only the first
(visible) 10 are populated with TAlbumItem components. The rest is done
in the OnScroll event of the ScrollPanel.

This sample uses 200 records and works quite well. But adding a larger
number of empty panels at startup takes too long. That's why I created
this thread.

Uli
Sun, Apr 8 2018 11:03 AMPermanent Link

Uli Becker

Mark,

meanwhile I found a better solution without creating empty panels at
all. It works really fast (tested with 2000 records):

Demo:
http://beckersoft-online.de:8070/myspotify/nopanels.html

The new approach creates the items directly on the ScrollPanel and
calculates its position from the ScrollTop value.
Every "row" that has been created is logged in an integer array. Before
creating a new item this array can be checked.

If you need the code, just tell me.

Cheers Uli
Mon, Apr 9 2018 6:29 AMPermanent Link

Mark Brooks

Slikware

Avatar

Uli Becker wrote:

>>meanwhile I found a better solution without creating empty panels at
>>all. It works really fast (tested with 2000 records):

Hi Uli - can you post the code for this version please?

As an aside, one of my issues is that my "panels" can be varying heights!
Mon, Apr 9 2018 5:22 PMPermanent Link

Uli Becker

Hi Mark,

> Hi Uli - can you post the code for this version please?

Sure, attached.

> As an aside, one of my issues is that my "panels" can be varying heights!

Then you will need to create panels as placeholders I think. When I've
some time left, I'll investigate that further and try to find a real
"virtual" solution which allows smooth scrolling.

The idea is to use just a small number of panels using layouts and move
the upper (invisible) row to the (invisible) bottom during scrolling
just by changing the layout order. No idea if that will work but I'll
put the result here anyway.

Cheers Uli




Attachments: Unit3.wbs
Mon, Apr 9 2018 5:56 PMPermanent Link

Mark Brooks

Slikware

Avatar

Cheers Uli - will have a play
Previous PagePage 2 of 2
Jump to Page:  1 2
Image