Positioning invisible components BUG or Feature? lazarus / 31-LCL ---------------------------------------------------------------------- ps · 2016-09-19 13:09 Why is diference between: Code for: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i MainPanel.Visible := False;for I := 0 to 10 do begin  SubPanel := TPanel.Create(Self);  SubPanel.Parent := MainPanel;  SubPanel.Align := alTop;  SubPanel.Top := 20000;  SubPanel.Height := 20;  SubPanel.Caption := 'Panel number: ' + IntToStr(I);end;MainPanel.Visible := True;Result is: Panel number: 10 Panel number: 9 Panel number: 8 ... Panel number: 1 But for visible MainPanel.Visible := True; (same code). Result is correct: Panel number: 1 Panel number: 2 ... Panel number: 10 Same problem is when creating components on form (for ex. OnCreate event); Under delphi both methods works same. Lazarus 1.6 FPC 3.0.0, Windows 32/64 bit. ---------------------------------------------------------------------- howardpc · 2016-09-19 15:15 This is a pseudo-problem. There is no reason why the LCL should be Delphi-compatible in these sorts of implementation details. If it is a problem to you, simply alter your code to something like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i MainPanel.Visible := False;    for I := 0 to 10 do begin      SubPanel := TPanel.Create(Self);      SubPanel.Parent := MainPanel;      SubPanel.Align := alTop;      SubPanel.Top := I; // < - - - note the change here      SubPanel.Height := 20;      SubPanel.Caption := 'Panel number: ' + IntToStr(I);    end;  MainPanel.Visible := True; ---------------------------------------------------------------------- ps · 2016-09-19 16:36 I'm trying Delphi only for test if this is feature. My problem is there is diference between visible and non-visible controls. Your solution don't work for me because in real code I have many BorderSpacing etc. so many calculation will be needed to fix this problem. And creating controls with Visible is slow. ---------------------------------------------------------------------- howardpc · 2016-09-19 17:03 In general it is not wise to parent child controls to invisible containers, and then later reset the visibility, because the invisible->visible change can have differing side-effects on different widgetsets. In the LCL it is better to set all properties needed except the Parent. Then set the Parent(s) as the very last step in initialisation. Delphi does not allow this (or did not allow it, perhaps things have changed). This LCL feature alone usually saves milliseconds if not seconds with large complex forms. Also using the Align property for multiple child controls is usually a sign of poor design. It is usually much better to use Anchors and ChildSizing for layouts involving more than one or two child controls. Can you show compilable code that demonstrates a real problem that you have? ---------------------------------------------------------------------- Thaddy · 2016-09-19 17:38 Easy: Form1, Mainpanel, subpanels. Subpanel one contains an array of buttons. Created at design time, or visible( the latter only on windows, a second panel will be below the ftrst one. Created in a loop it behaves different. That's a bug. Align := caTop forgets to calculate its proper position relative to the other controls. I mean that: it is a proper bug. On linux it is always the other way around creted at runtime. So at least there the bug is consistently different from design time. I can confirm Delphi has exactly the same behavior at runtime, visible or not visible, and at runtime, visible or not visible. And this is absolutely not implementation detail. Nor is it a feature nor has it much to do with speed. It is also not a compiler induces optimization (loop reversal). Its a BUG. The LCL should respect intention in its implementation. IOW it should respect creation order as drawing order, it should respect toggling align:= false or true as well.The creatiopn  order is readily available in the Children list. The paint order should rely on that Here the intention is to keep the same order as expected when designing by hand. ---------------------------------------------------------------------- howardpc · 2016-09-19 18:04 Quote from: ps on September 19, 2016, 06:36:43 pmYour solution don't work for me because in real code I have many BorderSpacing etc. so many calculation will be needed to fix this problem. And creating controls with Visible is slow. The  BorderSpacing value for each child control has no effect on the layout positioning order. No extra calculations are needed at all. See for yourself, add a line like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i for I := 0 to 10 do begin      SubPanel := TPanel.Create(Self);      subPanel.BorderSpacing.Around:=Random(12); // - - > add this line    SubPanel.Parent := MainPanel;      SubPanel.Align := alTop;      SubPanel.Top := I;      SubPanel.Height := 20;      SubPanel.Caption := 'Panel number: ' + IntToStr(I);    end; ---------------------------------------------------------------------- ps · 2016-09-26 12:58 Thank's for your solution, your code work (without random BorderSpacing , due to random AV (loop detection)). But there is still diference between visible and non visible (order is changed). But I can live with this if this is not bug. ChildSizing is very interesting for me, but I can't find solution to have different height for controls. ---------------------------------------------------------------------- howardpc · 2016-09-26 14:09 Thaddy, who knows far more than me about these things, considers the visible/invisible ordering difference a bug. In which case the code I gave must be considered a workaround. I see no sign of this 'bug' getting fixed, so I have tended to regard it as an LCL feature. Since I don't use Delphi I'm generally unaware of incompatabilities between Lazarus and Delphi. Childsizing as far as I know is designed to place controls in a simple grid pattern. So, no, it does not provide for controls of different height. To achieve such complex layouts requires hand-coding. And often what works on one widgetset then behaves slightly differently on another. Getting flawless GUI layouts crossplatform across different widgetsets/OSs with differing screen dpi settings and different themes and window managers can be a daunting task.