Jump to content
Alberto Miola

Efficient list box items with Frames

Recommended Posts

I have to create a Delphi program and since it's going to run only under Windows, I'm going to use VCL instead of FMX. This is an example of a program that I have made using another library (it's called Qt, it uses C++).

Check this picture: https://i.imgur.com/6owIISN.png

 

I'd like to do something like this with VCL. Basically the picture shows that there is a black container and I can put inside it the green rectangle (some objects with an associated "view"). How can this be done with VCL?

 

I have thought that I could create a Frame, put on it the 2 buttons and a label. But then how can I place the frames in the listbox? Do I have to switch to FMX?

 

Thanks

 

 

Share this post


Link to post

Ok after some googling I have tried this and it works, but it's under FMX and NOT VCL.


 

procedure TForm2.FormCreate(Sender: TObject);
var
  items: array[0..9] of TListBoxItem;
  i: integer;
  frame: TFrame1;
begin
  Randomize;

  for i := 0 to 10 do
    begin
      items[i] := TListBoxItem.Create(Self);
      items[i].Selectable := false;
      items[i].Height := 100;

      frame := TFrame1.Create(Self);
      frame.Name := 'Test' + IntToStr(i);
      frame.Parent := items[i];

      ListBox1.AddObject(items[i]);
    end;
end;

 

This works fine; I can fill the listbox with many items created as a frame. See the result: http://prntscr.com/ndtuhh

Can I do the same with VCL?

 

If no, I will use Firemonkey but I'd prefer using VCL because I think that FMX is pretty broken (I've had bad times with android and ios)

Share this post


Link to post
12 hours ago, Alberto Miola said:

I have thought that I could create a Frame, put on it the 2 buttons and a label. But then how can I place the frames in the listbox? Do I have to switch to FMX?

Using a TFrame is fine, but you can't combine that with a VCL TListBox. Putting the TFrame objects onto a TPanel or even a TScrollBox would make more sense.

Edited by Remy Lebeau
  • Thanks 1

Share this post


Link to post
12 hours ago, Alberto Miola said:

If no, I will use Firemonkey but I'd prefer using VCL because I think that FMX is pretty broken (I've had bad times with android and ios) 

VCL is not designed to such approach. What if your listbox contains 1 Million items? Each t would contain 2 buttons?

You need to owner-draw listbox items to achieve that, and add mouse interaction with active item -- yes, manually.

Or use some third-party rendering. Say, free htmlviewer can do that, I guess. Html components (paid) would do that, too

Share this post


Link to post
13 hours ago, Alberto Miola said:

I have to create a Delphi program and since it's going to run only under Windows, I'm going to use VCL instead of FMX. This is an example of a program that I have made using another library (it's called Qt, it uses C++).

Check this picture: https://i.imgur.com/6owIISN.png

 

I'd like to do something like this with VCL. Basically the picture shows that there is a black container and I can put inside it the green rectangle (some objects with an associated "view"). How can this be done with VCL?

 

I have thought that I could create a Frame, put on it the 2 buttons and a label. But then how can I place the frames in the listbox? Do I have to switch to FMX?

 

Thanks

 

 

Instead of a listbox, use the VCL TScrollbox as container for the frames.

Share this post


Link to post

Talking about alternative controls: There is also TStringGrid/TDrawGrid + owner drawing. There are various examples on how to add additional controls to the cells. Not sure whether it fits the bill though.

  • Thanks 1

Share this post


Link to post

I would def not use a TListbox for that purpose. 

 

Check out TFlowPanel or TGridPanel. I think one of them would be best suited for what you're looking for. Maybe on a TScrollPanel.

 

https://stackoverflow.com/questions/3254026/how-can-i-scroll-the-content-of-a-tflowpanel

 

I don't know off-hand if I'd use something derived from a TFrame or TPanel for the inner blocks, but I'd probably try the TPanel first, just because TFrames can be a PITA to deal with at design time.

 

There's also this:

 

https://torry.net/pages.php?s=79

 

Look for: "DictaSoft Layout Pack v.1.0"

 

Edited by David Schwartz

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×