Lazarus

Programming => LCL => Topic started by: trev on June 14, 2019, 11:54:42 am

Title: [SOLVED] Delphi TListBoxGroupHeader- alternatives?
Post by: trev 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]
Title: Re: Delphi TListGroupHeader- alternatives?
Post by: wp on June 14, 2019, 12:24:52 pm
In Delphi 10.2 Community Edition I cannot find a TListGroupHeader component.
Title: Re: Delphi TListGroupHeader- alternatives?
Post by: trev on June 14, 2019, 12:32:26 pm
Oops, TListBoxGroupHeader.
Title: Re: Delphi TListBoxGroupHeader- alternatives?
Post by: wp 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.
Title: Re: Delphi TListGroupHeader- alternatives?
Post by: ASerge 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.
Title: Re: Delphi TListBoxGroupHeader- alternatives?
Post by: trev 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. 
Title: Re: Delphi TListBoxGroupHeader- alternatives?
Post by: wp 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.
Title: Re: Delphi TListBoxGroupHeader- alternatives?
Post by: trev 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 :(
Title: Re: Delphi TListBoxGroupHeader- alternatives?
Post by: wp 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...
Title: Re: Delphi TListBoxGroupHeader- alternatives?
Post by: trev 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.
Title: Re: Delphi TListBoxGroupHeader- alternatives?
Post by: lucamar 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 (https://wiki.freepascal.org/Anchor_Sides) and related for more info.
Title: Re: Delphi TListBoxGroupHeader- alternatives?
Post by: wp 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...).
Title: Re: Delphi TListBoxGroupHeader- alternatives?
Post by: trev 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  :)
Title: Re: [SOLVED] Delphi TListBoxGroupHeader- alternatives?
Post by: trev on June 20, 2019, 11:50:50 am
Yep, I went with labels and combo boxes. Thanks again.
Title: Re: [SOLVED] Delphi TListBoxGroupHeader- alternatives?
Post by: lucamar 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 :)
Title: Re: [SOLVED] Delphi TListBoxGroupHeader- alternatives?
Post by: trev on June 20, 2019, 03:05:32 pm
No, I just created the labels and combo boxes dynamically, incrementing the position in the scroll box, depending on the number required for the selected data file.