Recent

Author Topic: Visual Component List Box ?  (Read 3352 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Visual Component List Box ?
« on: June 28, 2021, 07:40:29 am »
Hello Guys,

so i wanted to create myself a List wich changes a Runtime.
In the attachment u can see how i currently handled it. I want to change this to 1 List where i can add for Example a Group box and then the next components i add will get added below the last one. If there are to much then a scrollbar should appear to go through all those fields. Not every field is shown for certain operations.

Is this somehow possible ?

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: Visual Component List Box ?
« Reply #1 on: June 28, 2021, 08:17:49 am »
Sorry, cannot fully understood what you said. Did you mean the items in "Anzahl Zonen" will be changed if user change the selected item in "CO2 oder VOC"?

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: Visual Component List Box ?
« Reply #2 on: June 28, 2021, 09:04:44 am »
Ignore the File.

I wanted to create a ListBox with scrollbar, but instead of Strings i wanted to add Controls like a TEdit or a GroupBox. The List has a maximum height (Length) wich when it getws full a scrollbar should appear.

Something like the normal ListBox but with Visual Components instead.

For Example if u Check a checkbox or press a button some information(the components) will appear in the ListBox.

Edit: To understand my problem: in my attached Picture u can see some Groupboxes. But when i need to extend those boxes there wont be enough space to display it so i thought about a List where u can scroll down to work around my space problems
« Last Edit: June 28, 2021, 09:08:59 am by Weitentaaal »

dseligo

  • Hero Member
  • *****
  • Posts: 1221
Re: Visual Component List Box ?
« Reply #3 on: June 28, 2021, 09:15:03 am »
Put your controls in a TScrollBox (it is in Additional tab in Lazarus' controls).

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Visual Component List Box ?
« Reply #4 on: June 28, 2021, 09:18:07 am »
Rather than a ListBox, which is somewhat specialized to manage strings, why don't you use a normal container like, say, a TScrollBox or even a TFlowPanel?

One might understand if you wanted a somewhat "extended" list of strings (e.g. with a check box for each string, like a TCheckListBox), but for arbitrary controls ...

Note also that you can easily extend a container with a normal object list, if you want it to manage the contained controls/components, so (mis-)using a list box shouldn't really be your first option, IMHO.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: Visual Component List Box ?
« Reply #5 on: June 28, 2021, 09:40:00 am »
Thanks Guys,

i didn't meant to use a ListBox i just wanted to compare it with my Goal.

Thanks again :)

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: Visual Component List Box ?
« Reply #6 on: June 28, 2021, 10:11:35 am »
A demo showing how to use TScrollBox.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, StdCtrls, ExtCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     ScrollBox1: TScrollBox;
  16.     ScrollBox2: TScrollBox;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure FormResize(Sender: TObject);
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. const
  27.   Spacing = 20;
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.FormCreate(Sender: TObject);
  34. var
  35.   LabelEdit: TLabeledEdit;
  36.   i:         Integer;
  37. begin
  38.  
  39.   ScrollBox1.Align                := alLeft;
  40.   ScrollBox1.BorderStyle          := bsNone;
  41.   ScrollBox1.BorderSpacing.Around := Spacing;
  42.   ScrollBox2.Align                := alClient;
  43.   ScrollBox2.BorderSpacing.Around := Spacing;
  44.   ScrollBox2.BorderStyle          := bsNone;
  45.  
  46.   LabelEdit                   := TLabeledEdit.Create(Self);
  47.   LabelEdit.Parent            := ScrollBox1;
  48.   LabelEdit.Top               := 20;
  49.   LabelEdit.Left              := 8;
  50.   LabelEdit.Width             := ScrollBox1.Width - 16;
  51.   LabelEdit.Anchors           := [akLeft, akRight, akTop];
  52.   LabelEdit.EditLabel.Caption := 'First Name';
  53.  
  54.   LabelEdit                   := TLabeledEdit.Create(Self);
  55.   LabelEdit.Parent            := ScrollBox1;
  56.   LabelEdit.Top               := 20 +50;
  57.   LabelEdit.Left              := 8;
  58.   LabelEdit.Width             := ScrollBox1.Width - 16;
  59.   LabelEdit.Anchors           := [akLeft, akRight, akTop];
  60.   LabelEdit.EditLabel.Caption := 'Last Name';
  61.  
  62.   LabelEdit                   := TLabeledEdit.Create(Self);
  63.   LabelEdit.Parent            := ScrollBox1;
  64.   LabelEdit.Top               := 70 +50;
  65.   LabelEdit.Left              := 8;
  66.   LabelEdit.Width             := ScrollBox1.Width - 16;
  67.   LabelEdit.Anchors           := [akLeft, akRight, akTop];
  68.   LabelEdit.EditLabel.Caption := 'Company';
  69.  
  70.   LabelEdit                   := TLabeledEdit.Create(Self);
  71.   LabelEdit.Parent            := ScrollBox1;
  72.   LabelEdit.Top               := 120 +50;
  73.   LabelEdit.Left              := 8;
  74.   LabelEdit.Width             := ScrollBox1.Width - 16;
  75.   LabelEdit.Anchors           := [akLeft, akRight, akTop];
  76.   LabelEdit.EditLabel.Caption := 'Street';
  77.  
  78.   LabelEdit                   := TLabeledEdit.Create(Self);
  79.   LabelEdit.Parent            := ScrollBox1;
  80.   LabelEdit.Top               := 170 +50;
  81.   LabelEdit.Left              := 8;
  82.   LabelEdit.Width             := ScrollBox1.Width - 16;
  83.   LabelEdit.Anchors           := [akLeft, akRight, akTop];
  84.   LabelEdit.EditLabel.Caption := 'City';
  85.  
  86.   for i := 1 to 7 do
  87.   begin
  88.     LabelEdit                   := TLabeledEdit.Create(Self);
  89.     LabelEdit.Parent            := ScrollBox2;
  90.     LabelEdit.Top               := -30 + i*50;
  91.     LabelEdit.Left              := 8;
  92.     LabelEdit.Width             := ScrollBox2.Width - 16;
  93.     LabelEdit.Anchors           := [akLeft, akRight, akTop];
  94.     LabelEdit.EditLabel.Caption := 'Item' + i.ToString;
  95.   end;
  96.  
  97. end;
  98.  
  99. procedure TForm1.FormResize(Sender: TObject);
  100. begin
  101.   ScrollBox1.Width := (Width - 3*Spacing) div 2;
  102. end;
  103.  
  104. end.

Change the line #27 to see the difference.
You can remove the line #40, #44 if you want the see the border.
And you should resize the form at runtime to see what will happen.
« Last Edit: June 28, 2021, 10:18:52 am by Handoko »

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: Visual Component List Box ?
« Reply #7 on: June 28, 2021, 11:06:51 am »
Thanks @Handoko for your Example, perfect to understand TScrollBox :)

 

TinyPortal © 2005-2018