Question

In this article there is an explanation of how to use TFrames as an alternative to TTabSheets in a Delphi PageControl.

I've been pondering a similar exercise, which the above doesn't seem to provide the solution for, and for which my solution seems to be overly complicated.

The requirement is for a tabbed interface, where each tab can be one of a number of different designs. Each design is implemented as a TFrame.

Due to the nature of the application being designed, we may have multiple copies of any frame open at any particular moment (with the content of each tab differing, but not the design) so that the user can compare the details of 2/3 different items at the same time.

For example in one session we may have 3 tabs open, all of Frame design A. On another occasion we may have 3 tabs open each of Frame A, B and C.

The design needs to be flexible enough that we can add Frames to the design on request.

At the moment the solution that I have is to have separate TLists managing each type of Frame that we have open, with perhaps a master TList to keep track of the tabs that are open. As I said, over complicated.

Does anyone have a suggestion of how this could be handled more simply?

Was it helpful?

Solution

I'd probably leave out the master TList of frame instances.

If you need them you'll be able to get them by interrogating the TPageControl directly or through each of your individual TLists for each frame type.

Apart from that your approach sounds reasonable.

OTHER TIPS

I have an application that manages frames on a single panel with my own menu control to control which frame is visible. When I need to make a frame visible I simple set visible:=false for every frame on the panel except for the one that I want. I am in control of what goes onto the panel so I know that at the very least each control is a Tframe and I can get to each frame by iterating over the Panel's Controls property. I then use interfaces to communicate between my main form and my frames.

Now if you want to use a standard windows tabbed interface you could still use the page control as you have suggested, you know that each TtabSheet has a single Tframe on it and you can check it's type and work with it as required. I don't see why you'd need a Tlist because if you really need to get at the "list of Tframes" you could build it dyamically anyway by iterating over the TtabSheets in the page control.

An alternative which would work similarly to my first approach, but gets you nice Windows tabs, would be to use a TtabControl instead of a TpageControl. With the TtabControl you basically just get a Tstrings instance (in the Tabs property) which represents all of the tabs. Since it's a Tstrings you can associate an object (ie your Tframe) with each item and hence each tab. When you click a tab you hide everything and show the correct Tframe. You also have your list because it's attached to the TtabControl via the Tabs property. You just have to handle the visibility of the frames yourself.

We use a TPageControl and create runtime a TTabSheet descendant, which has a new property for our own TFrame (we do not need to scan through .Controls or .Components to search our frame each time).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top