TScrollBox and TCheckListBox lazarus / 31-LCL ---------------------------------------------------------------------- dahaiou · 2012-08-31 16:05 I want to dynamically create a variable number of checkboxes and be able to scroll up and down in the list and set and unset them during execution. I have been able to do this using a TScrollBox but I can't seem to get it to scroll as I move the scrollbar. In fact, the scroll area is frozen while I move the scrollbar and it will not scroll to its new position until I release the mouse button, and when I do, it happens instantaneously. Setting HorScrollbar.Smooth to True and other settings I have fiddled with in the IDE apparently have no effect on this. So, question: Is there a way to make TScrollBox scroll smoothly as you move the scrollbar up and down (the way a TEdit does) ? The other alternative is to use  a TCheckListBox, which seems to scroll half-smoothly (not totally smooth - it jumps one scrollbox at a time but it is still an improvement over TScrollBox ). However here I run into a number of other difficulties: - By reading the docs I cannot get my mind around how to actually use a TCheckListBox - I can't see how I can set/read the individual checkboxes - I can't find a way to separate the individual checkboxes from each other and from the edge of the TCheckListBox area. They are crammed together too tight. The various Borderspacing options in the IDE don't seem to have any effect on this. Can anyone point me at example code where TCheckListBox is used dynamically? Other advice on the above points would be appreciated too. ---------------------------------------------------------------------- Avishai · 2012-08-31 16:40 For Smooth Vertical Scrolling go to property 'VertScrollBar' and set property Smooth:= True. ---------------------------------------------------------------------- dahaiou · 2012-08-31 16:57 Thanks but no, it doesn't. That's what I said above. None of those settings have any effect! (though I said Horizontal by mistake when I meant Vertical). The section VertScrollBar has the following subsections in the IDE:  - Increment  - Page  - Position  - Range  - Smooth  - Tracking  - Visible I have played around with different settings for Increment, Page, Smooth and Tracking and have not seen any effect on how the control behaves on screen. PS. In fact, I played around with it some more and now I lost the vertical scrollbar altogether and can't get it back. hmpf :ox I tried setting the vertical scrollbar to visible and smooth in code as well, but I still can't see it. And I could see it a moment ago. Here's the test code I am using btw. This is run on creation of the main form. The various checkboxes are created OK, it's just the scrollbar that is acting up: Code: [Select]  SetLength (arrDbgCatCheckBoxes, 20);   for i := 0 to 19 do begin     arrDbgCatCheckBoxes [i] := TCheckBox.create (scrollDbgCats);     with arrDbgCatCheckBoxes [i] do begin       Caption := 'cbDbgCat' + inttostr(i);       Parent := scrollDbgCats;       if i<=0 then begin         BorderSpacing.Top  := 2;         BorderSpacing.Left := 4;         AnchorSide[akTop].Control:=Parent;         AnchorSide[akTop].Side:=asrTop;         AnchorSide[akLeft].Control:=Parent;         AnchorSide[akLeft].Side:=asrLeft;       end else begin         BorderSpacing.Top  := 2;         BorderSpacing.Left := 0;         AnchorSide[akTop].Control:=arrDbgCatCheckBoxes [i-1];         AnchorSide[akTop].Side:=asrBottom;         AnchorSide[akLeft].Control:=arrDbgCatCheckBoxes [0];         AnchorSide[akLeft].Side:=asrLeft;       end;     end;   end;   scrollDbgCats.VertScrollBar.Visible := True;   scrollDbgCats.VertScrollBar.Smooth  := True; ---------------------------------------------------------------------- Avishai · 2012-08-31 17:02 What is your OS and Lazarus/FPC versions.  It works perfectly on my system with Win7-64. Lazarus 38402 and FPC 2.61 Edit: You must also set 'Tracking' to True. ---------------------------------------------------------------------- dahaiou · 2012-08-31 17:28 Lazarus 0.9.30.4 r35940 FPC 2.6.0 i386-win32-win32/win64 NOW I got it working, but this is really WEIRD ! The key seems to be with the AutoScroll property. What I do now is set AutoScroll to False in the IDE, then set it to True in code just after creating the checboxes. This way I get the smooth scrolling that I want. EDIT: Correcting myself: Actually, it doesn't have to be after creating the checkboxes. It can be set to True anywhere in the Form.Create procedure. It does NOT work if I first set AutoScroll to False in code, only when it is set from the IDE. (And if I set it to True in the IDE I get the non-smooth clunky scrolling I described before) here is the modified code: Code: [Select]  scrollDbgCats.AutoScroll                := False;   // Note: Setting AutoScroll to False here has no effect.   //       it _has_ to be set to False from the IDE and then   //       set to True after creating the checkboxes. See below   // Here we create 20 checkboxes   SetLength (arrDbgCatCheckBoxes, 20);   for i := 0 to 19 do begin     arrDbgCatCheckBoxes [i] := TCheckBox.create (scrollDbgCats);     with arrDbgCatCheckBoxes [i] do begin       Caption := 'cbDbgCat' + inttostr(i);       Parent := scrollDbgCats;       if i<=0 then begin         BorderSpacing.Top  := 2;         BorderSpacing.Left := 4;         AnchorSide[akTop].Control:=Parent;         AnchorSide[akTop].Side:=asrTop;         AnchorSide[akLeft].Control:=Parent;         AnchorSide[akLeft].Side:=asrLeft;       end else begin         BorderSpacing.Top  := 2;         BorderSpacing.Left := 0;         AnchorSide[akTop].Control:=arrDbgCatCheckBoxes [i-1];         AnchorSide[akTop].Side:=asrBottom;         AnchorSide[akLeft].Control:=arrDbgCatCheckBoxes [0];         AnchorSide[akLeft].Side:=asrLeft;       end;     end;   end;   scrollDbgCats.AutoScroll                := True; // Essential to achieve smooth scrolling //  scrollDbgCats.VertScrollBar.Smooth      := True; // Not essential here, set to smooth from IDE PS. Anyway, since I got it to work I guess I don't need any more help for now. But if anyone has any ideas about the WEIRD behaviour as described above it would be interesting to hear about it all the same. Thanks for the input.