Delphi - Issue rendering TPanel descendant in TScrollBox (32K pixel limit)

240 views Asked by At

I am new here and hope that I am following the right protocol and asking the question correctly. I am posting this question separately here as I do not have the appropriate privileges to post a comment against the original issue listed/linked below.

I ran into this issue (Delphi - TScrollBox issue after X number of components) and tried to implement the first solution (scrolling the scrollbox) suggested by @ngln.

I must be doing something wrong, as my implementation of the solution does not seem to work. Would really appreciate some guidance on this.

I have a custom Panel (TEntryPanel) which is derived from TPanel - and contains other elements inside of it which get set using the data from TEntry (which is just a custom class derived from TObject that contains the data). EntryList is an object that contains a list of TEntry objects.

Here's how I implemented it:

  count:=EntryList.Count;
  SendMessage(scroll_left.Handle, WM_SETREDRAW, 0, 0);
  scroll_left.VertScrollBar.Range:=(count-1)*83;
  scroll_left.DisableAlign;
  try
    //Display all the panels
    prevtop:=0;
    counter:=0;
    incscrollpos:=0;
    for i:=Count-1 downto 0 do
    begin
      //New Code--- based on https://stackoverflow.com/questions/14655516/delphi-tscrollbox-issue-after-x-number-of-components
      //for every entry in the list
      entry:=EntryList.ListofEntries[i];
      //we create a panel
      pnl:=TEntryPanel.Create(self);
      //set it's top location
      pnl.SetBounds(0, prevtop, 350, 83);
      pnl.Align:=alCustom;
      //set the entry of the panel
      pnl.SetEntryData(entry);
      //set the events
      pnl.OnClick:=pnlOnClick;
      pnl.SetChildrenClickEvent;
      scroll_left.InsertComponent(pnl);
      pnl.parent:=scroll_left;
      //increment the top location
      prevtop:=prevtop+pnl.height;
      //and the component index
      pnl.componentindex:=Count-1-i;
      counter:=counter+1;
      if (counter div 350) <> incscrollpos then
      begin
        incscrollpos:=incscrollpos+1;
        scroll_left.VertScrollBar.Position := incscrollpos*350*83;
      end;
      //New Code ---
  finally
    scroll_left.VertScrollBar.Position:=0;
    scroll_left.EnableAlign;
    SendMessage(scroll_left.Handle, WM_SETREDRAW, 1, 0);
    RedrawWindow(scroll_left.Handle, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ALLCHILDREN);
  end;

After running this code, I still have the issue wherein all of the panels are not being displayed. Could someone please let me know what I am doing wrong? I am using Delphi 10.1 Berlin. Many thanks in advance.

0

There are 0 answers