5

I've got a dialog that's laid out something like this:

---------------------------------------------
|                                           |
| CONFIG AREA                               |
| Align: alTop                              |
--------------------------------------------- <-static boundary
|                                           |
| DISPLAY AREA 1                            |
| Align: alTop                              |
============================================= <-TSplitter Align: alTop
|                                           |
| DISPLAY AREA 2                            |
| align: alClient                           |
--------------------------------------------- <-bottom of dialog

However, at runtime, the splitter doesn't show up between Display Area 1 and Display Area 2, but between Config Area and Display Area 1, leading to some annoying interface problems. There's nothing in the form's setup-related event handlers that alters the Visible or Align properties of any of these components. Does anyone know why the splitter isn't loading in the place it's positioned at in the form designer?

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
  • 1
    From what you are showing, it should work as expected. Only thing that comes to mind are constraints, margins (if auto size with margins to true) and the splitter's MinSize property. I recently had all sorts of fun with form's growing unexpectedly because a splitter's MinSize got "honoured" at the wrong time. I'd check that the Splitters MinSize is default and smaller than the height of Config+Display and smaller than the (initial) height of Display2. Similar checks for Constraints / Margins. Other possiblity: Explicit Height's getting their grubby fingers in the mix. – Marjan Venema Mar 11 '11 at 18:44
  • On second thought: @GameCat's explanation is probably what is happening. If the order in the dfm does not reflect the order on screen, the splitter can end up where you do not expect it. – Marjan Venema Mar 11 '11 at 18:46

3 Answers3

11

(Can't reproduce.) Splitters are tricky things. I always write code to position them. In this case, I would do

procedure Form1Show(Sender: TObject);
begin
  Splitter1.Top := DisplayArea2.Top;
end;
Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • 4
    Choosing this rather than the Gamecat's solution because having explicit code in FormShow makes it less likely that someone poking the wrong thing in the form designer at a future point will do something that somehow breaks the fragile creation order that his solution relies on. – Mason Wheeler Mar 11 '11 at 18:56
  • +1 this kind me stuff always works better in code than the designer – David Heffernan Mar 11 '11 at 19:00
  • Smart move, you can shoot yourself in the foot quite easily while playing with the dfm files. But sometimes it is the easiest way to go. – Toon Krijthe Mar 11 '11 at 20:45
7

I have had similar problems in the past. They were cause by:

  1. controls that where made invisible.
  2. control creation order.

I think the splitter is created after config area and before display area1. If you create it after display area 1 it should be fine.

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
6

I also had the same problem in the past. TSplitter should be placed between two TPanel, like such:

+---------------------------------------------+
|+-------------------------------------------+|
||                                           ||
|| CONFIG AREA                               ||
|| Align: alTop                              ||
|+-------------------------------------------+|
||                                           ||
|| DISPLAY AREA 1                            ||
|| Align: alClient                           ||
|+-------------------------------------------+|
+---------------------------------------------+
=============================================== <-TSplitter Align: alTop
|                                             |
| DISPLAY AREA 2                              |
| align: alClient                             |
----------------------------------------------- <-bottom of dialog

Config Area and Display Area 1 should now be contained inside a TPanel with Align := alTop and either the Config Area or the Display Area 1 should be aligned to alClient.

Hope this helps

Jose Rui Santos
  • 15,009
  • 9
  • 58
  • 71