Recent

Author Topic: [SOLVED] Delphi TListBoxGroupHeader- alternatives?  (Read 1018 times)

trev

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 10.2 User
[SOLVED] Delphi TListBoxGroupHeader- alternatives?
« on: June 14, 2019, 11:54:42 am »
I am in the final throes of porting my application from Delphi 10.2.1 to Lazarus 2.02 on macOS.

In the Delphi version, I populate a dynamically created TList with TListGroupHeaders (for option names) and a TComboBox (for option values) re-parented to the TListBoxGroupHeader.

See attached image.

Alas, there is no TListGroupHeader for Lazarus' TList and TListItems cannot be parents.

Any ideas as to an alternative approach?

[Edit fixed component name]
« Last Edit: June 20, 2019, 11:48:37 am by trev »
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

wp

  • Hero Member
  • *****
  • Posts: 6312
Re: Delphi TListGroupHeader- alternatives?
« Reply #1 on: June 14, 2019, 12:24:52 pm »
In Delphi 10.2 Community Edition I cannot find a TListGroupHeader component.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

trev

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 10.2 User
Re: Delphi TListGroupHeader- alternatives?
« Reply #2 on: June 14, 2019, 12:32:26 pm »
Oops, TListBoxGroupHeader.
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

wp

  • Hero Member
  • *****
  • Posts: 6312
Re: Delphi TListBoxGroupHeader- alternatives?
« Reply #3 on: June 14, 2019, 02:35:22 pm »
I've never used this component, but your screenshot looks as if a plain old TStringGrid with Dropdown cell editors could do the job.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

ASerge

  • Hero Member
  • *****
  • Posts: 1411
Re: Delphi TListGroupHeader- alternatives?
« Reply #4 on: June 14, 2019, 03:24:33 pm »
Oops, TListBoxGroupHeader.
TListBoxGroupHeader is a component of the FMX framework. But the LCL uses the native OS, so that in Lazarus there is no support for FMX.
Try to describe the functionality that you have with this component, perhaps then you will be prompted with possible solutions.

trev

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 10.2 User
Re: Delphi TListBoxGroupHeader- alternatives?
« Reply #5 on: June 14, 2019, 03:33:08 pm »
@wp: I'll investigate the TStringGrid and cell combo boxes. It looks like it should do the job nicely. Thanks!

@aserge: TListBoxGroupHeader is a ListBox Header. Adding multiple to a ListBox stacks them nicely one above the other and they can be parents of a combobox. See the screenshot. The option name is a left-aligned text property of the ListBoxGroupHeader to which I've right-aligned a combobox which holds the values for the option to the left. 
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

wp

  • Hero Member
  • *****
  • Posts: 6312
Re: Delphi TListBoxGroupHeader- alternatives?
« Reply #6 on: June 14, 2019, 03:43:07 pm »
I've never used this component, but your screenshot looks as if a plain old TStringGrid with Dropdown cell editors could do the job.
An alternative solution would be to use individual labels and comboboxes aligned by the Anchor editor.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

trev

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 10.2 User
Re: Delphi TListBoxGroupHeader- alternatives?
« Reply #7 on: June 14, 2019, 04:01:45 pm »
An alternative solution would be to use individual labels and comboboxes aligned by the Anchor editor.

I did try that, but ended up with all the labels and combo boxes on one line :(
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

wp

  • Hero Member
  • *****
  • Posts: 6312
Re: Delphi TListBoxGroupHeader- alternatives?
« Reply #8 on: June 14, 2019, 05:45:45 pm »
No, you must select the corresponding button in the anchor editor. See attached demo. I put the labels and comboboxes into a scrollbox to have a scrollbar when the list is long - this perfectly mimics a listbox. Of course, setting the anchors for labels and comboboxes in the anchor editor is a bit tedious...
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

trev

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 10.2 User
Re: Delphi TListBoxGroupHeader- alternatives?
« Reply #9 on: June 15, 2019, 03:15:04 am »
No, you must select the corresponding button in the anchor editor. See attached demo.

Ah yes, unfortunately I have to generate the labels and combo boxes dynamically. The user makes a choice, a file is read, parsed and then the option names and option value components are created - the number of options varies from three to over 32.
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

lucamar

  • Hero Member
  • *****
  • Posts: 2075
Re: Delphi TListBoxGroupHeader- alternatives?
« Reply #10 on: June 15, 2019, 11:52:10 am »
No, you must select the corresponding button in the anchor editor. See attached demo.

Ah yes, unfortunately I have to generate the labels and combo boxes dynamically.

Note that whatever the IDE many tools do is ultimately translated some way or other to code.

In the case of the anchor editor, the tool serves to edit easily the Anchors, AnchorSides and BorderSpacing properties of the afected controls, but nothing prevents you from setting them in code.

See the wiki page Anchor sides and related for more info.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

wp

  • Hero Member
  • *****
  • Posts: 6312
Re: Delphi TListBoxGroupHeader- alternatives?
« Reply #11 on: June 15, 2019, 01:50:17 pm »
Yes, lucamar is right, it takes only a few lines of code to create an arbitrary number of label-combobox combinations. And you even don't need the anchoring properties - see attached demo (Well, ok, it's a bit too simple because the left edge of the comboboxes does not adjust itself to the longest label in the demo, I was too lazy to add this...).
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

trev

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 10.2 User
Re: Delphi TListBoxGroupHeader- alternatives?
« Reply #12 on: June 15, 2019, 02:47:29 pm »
Duh. I should have known that.  :o

Thanks lucamar and especially thanks wp for providing code.

Now I'm torn  :-\  I just spent most of the day getting to grips with TStringGrids which I'd never used before that I recall (apart from this application, the last time I programmed in Lazarus/Delphi was 12 years ago).

I think this solution is probably the closest to what I had in Delphi and simpler... I'm going to have to sleep on it  :)
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

trev

  • Full Member
  • ***
  • Posts: 220
  • Former Delphi 7 and Delphi 10.2 User
Re: [SOLVED] Delphi TListBoxGroupHeader- alternatives?
« Reply #13 on: June 20, 2019, 11:50:50 am »
Yep, I went with labels and combo boxes. Thanks again.
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

lucamar

  • Hero Member
  • *****
  • Posts: 2075
Re: [SOLVED] Delphi TListBoxGroupHeader- alternatives?
« Reply #14 on: June 20, 2019, 02:44:59 pm »
Nice!

Did you make it into a class/control of your own? And if so, do you mind sharing the code? Sounds like a handy, useful thing :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.