Recent

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

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 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 »

wp

  • Hero Member
  • *****
  • Posts: 11857
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.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Delphi TListGroupHeader- alternatives?
« Reply #2 on: June 14, 2019, 12:32:26 pm »
Oops, TListBoxGroupHeader.

wp

  • Hero Member
  • *****
  • Posts: 11857
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.

ASerge

  • Hero Member
  • *****
  • Posts: 2223
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 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. 

wp

  • Hero Member
  • *****
  • Posts: 11857
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.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 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 :(

wp

  • Hero Member
  • *****
  • Posts: 11857
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...

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 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.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
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/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.

wp

  • Hero Member
  • *****
  • Posts: 11857
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...).

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 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  :)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 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.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
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/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.

 

TinyPortal © 2005-2018