Recent

Author Topic: Layout problem by nested TPageControls  (Read 1411 times)

Nicole

  • Hero Member
  • *****
  • Posts: 1219
Layout problem by nested TPageControls
« on: June 12, 2025, 05:08:47 pm »
Lazaus 4 in Linux.

I have a Page Control with side tabs = Tabsheets.

Each leads to other pagecontrol with other tabsheets.
And so on. It is nested heavily.

One form I had to give up. Anything exploded and covered all other. I could not find the reason and started a new project.

I did it by adding the TPageControls and add and add. To have a nice view I set them to alClient. Started, looked great. Then I wanted to polulate them. I added a TImage. And could not resize it. A check showed me, that it was anchored on 4 sides. I removed the ancor (shall I do this for 100 components?) and - could not resize is neither. I tried a lot, but the thing is not rocking.

How to work with it?
I can set the alclient at runtime, but then I will not see, how it looks alike at design-time.
And however: Clicking one time too often at aclClient seems to mess the whole generation with all chirldren without chance of re-doing it. The strange behaviour of the children components stay.

And it is not easy to work with it at all. The IDE freezes for minutes, tells me "dividsion by zero" after that long a time. I spend the majority of my time by waiting for the IDE reaction. Every attempt of resizing goes in huge steps if it works at all and never has the wanted size-results.

I come from Lazarus 3.0 under windows 7, which does not behave like this.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11487
  • Debugger - SynEdit - and more
    • wiki
Re: Layout problem by nested TPageControls
« Reply #1 on: June 17, 2025, 10:35:44 pm »
I don't know how the anchors for your image came to be ...

But the "takes long" / "div 0" are signs of a circular sizing loop. Either by the way anchors are set. Or by the way the OS reacts (which could be a Linux/Win difference, or a Laz 3 vs Laz 4 diff).


In a bit more detail.



"div 0" => this is a left over of days long gone. It is basically an alternative way of throwing an exception. At some time (maybe 20 years ago), when gdb was the only debugger, and the IDE support for gdb was still very early, back then the debugger could not catch "raise exception". So "div 0" is a "gdb catchable exception".
That said, "div 0" can happen in actual code too, but there is a good chance the one you are seeing is a disguised exception.
Of course that does not help much. If it were fixed, then you would get some exception instead.



The part were it takes long before that exception... Say you have 10 controls, and they all are meant to be 10 pixel left after the control before them, and then the first one should be 10 pixels left from the last.
That is obviously not possible.
That will throw an exception (or sometimes a "div 0").

Similar, if a Panel autosizes to its children, but the children depend their size on that panel....

Usually such circle are quickly found though.

It is possible that when you go through different align settings, that one of the ones you cycle through leads to such a violation...



But as I said, the above is usually detected more quickly.

The other loop happens when the OS does not behave.

Say the LCL computes that some control should be 50 pixel width, and sends that to the OS. But the OS returns and says, I had to make it 52 pixels.

So then the LCL goes and computes all dependent controls to match that size (e.g. alclient children, or anchored siblings).
Now the LCL sets the alClient child to the new size.
But the OS reacts to that saying, I made the parent 54 pixel.... And so on...

Then that takes some time, because the LCL goes through a lot of iterations of that game before it gives up with an exception or "div 0".



The last bit could be different depending on OS.

But it could also be that something changed in the communication between LCL and all/any OS, and that the LCL now triggers that in some unforeseen case.



Of course those are only possibilities. I can't tell for sure.

If you have a reproducible case...
I don't know if I can look at it right away, but you can also always upload it to the bugtracker.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11487
  • Debugger - SynEdit - and more
    • wiki
Re: Layout problem by nested TPageControls
« Reply #2 on: June 17, 2025, 10:42:13 pm »
While this may not be the problem at all: Do you use embedded form designer?

If yes, try to switch it off for the time being. It is still relatively new. So it is possible it has bugs that the normal floating designer does not have.

It can be turned off in  Tools > Options.

Nicole

  • Hero Member
  • *****
  • Posts: 1219
Re: Layout problem by nested TPageControls
« Reply #3 on: June 18, 2025, 08:51:24 am »
Nothing embedded, all very basic, created at designtime.

But the explanations brought me to another idea. There is a very strange error message of VMWare "your host does not allow 3 D acceleration", this is a cheat, it allows. However, it is not within the OS of Windows, but somewhere in the graphic card driver. May be, VMWare checks the OS and does not take it from the graphic-card driver. This error message only comes, when I start the Linux VM. The Win 7 VM does not show it.

And there is one more point: DirektX. I have DirectX 12, VMWare needs some elements of DirectX 11, what I installed additionally. I was told that this should work. It works in terms of "directX error message gone", but may be this is a problem as such.

about the TPageControls: It was nothing wrong with them. I took the code from Lazarus 4, opened it in Lazarus 3 and it worked. So neither the TPageControls nor the TImageList seems to be the problem. The only difference: I arranged the tabs left. The fonts changed orientation from vertical to horizontal. Not sure, if this is of any importance or just an improvement in Lazarus 4.

It is all about Lazarus 4 on the Linux Mint VM.
Not sure, if I shall just delete and forget it.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11487
  • Debugger - SynEdit - and more
    • wiki
Re: Layout problem by nested TPageControls
« Reply #4 on: June 18, 2025, 10:50:30 am »
It is all about Lazarus 4 on the Linux Mint VM.
Not sure, if I shall just delete and forget it.

And Lazarus 3 on the same Linux Mint VM works?

Then it would be very desirable to have a reproducible example in a bug report.

Nicole

  • Hero Member
  • *****
  • Posts: 1219
Re: Layout problem by nested TPageControls
« Reply #5 on: June 18, 2025, 05:12:36 pm »
Unfortunately I cannot say. My Lazarus 3 runs on the Win 7 VM.
My direction was forward with new versions of all my software.

In the meanwhile, I quit the work on Linux, because it costed hours and days while my work made no progress.

etrusco

  • New Member
  • *
  • Posts: 17
Re: Layout problem by nested TPageControls
« Reply #6 on: June 18, 2025, 07:55:44 pm »
(...)
But the explanations brought me to another idea. There is a very strange error message of VMWare "your host does not allow 3 D acceleration", this is a cheat, it allows.
(...)
This means the card/driver isn't supported by VMware for VM 3D acceleration, not that no "3D card" is present. Host OS configuration may also interfere (Hyper-V, core isolation, WSL2, etc)
There's no warning when you run the Win7 guest probably because the required driver isn't installed in your Win7 image.

Quote
about the TPageControls: It was nothing wrong with them. I took the code from Lazarus 4, opened it in Lazarus 3 and it worked. So neither the TPageControls nor the TImageList seems to be the problem. The only difference: I arranged the tabs left. The fonts changed orientation from vertical to horizontal. Not sure, if this is of any importance or just an improvement in Lazarus 4.

It is all about Lazarus 4 on the Linux Mint VM.
What release and what flavor (Cinnamon, Mate, etc)?

Quote
In the meanwhile, I quit the work on Linux, because it costed hours and days while my work made no progress.
This is wise, you should change one variable at a time (if changing all of them at the same time doesn't work at first).
And changing the UI to avoid using nested PageControls would probably be a better option ;-)

CharlyTango

  • Full Member
  • ***
  • Posts: 148
Re: Layout problem by nested TPageControls
« Reply #7 on: June 19, 2025, 09:49:25 pm »
Starting from a TPageControl that branches out more and more and ends in a confusing orgy of controls, the point is reached where you have to structure things more clearly.

This is very easy if you know that you can easily "glue" complete forms (TForm) or frames (TFrame) into such a page control.

The secret is that you have to do this at runtime, otherwise you get more problems than you want. Especially when it comes to frames.
I would suggest starting with TForms first, because TForms already has all the known events

If you like i have attached a demo tabbed UI using Jedi Tools.

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.AddOneTab;
  2. var
  3.   aForm: TForm1;
  4. begin
  5.   aForm:=TForm1.Create(self);
  6.   aForm.Parent := tsxyTabsheet;  //The Tabsheet in which the form will be glued
  7.   aForm.BorderStyle:=bsNone;
  8.   aForm.Align:=alclient;
  9.   aForm.Show;
  10. end;

In this way, the individual TForms can also be tested individually, the whole thing becomes much clearer and you have less code in a single form.

If necessary, you can also create a separate ancestor for similar forms, which outsources further code.

Of course, you also have to take care of the accesses from a pasted form to the outside or actions from the outside into the form, but that's another topic again
« Last Edit: June 19, 2025, 10:12:19 pm by CharlyTango »
Lazarus stable, Win32/64

Nicole

  • Hero Member
  • *****
  • Posts: 1219
Re: Layout problem by nested TPageControls
« Reply #8 on: June 19, 2025, 10:34:03 pm »
This I do similar:

At design time I prepare the containers, the TPageControls. My software is developed in frames.
The practice has shown, that it has advantages to place a TPanel at every TabSheet instead of letting the TTabSheet become the parent by itself.

Code: Pascal  [Select][+][-]
  1. procedure TFormMain.FormCreate(Sender: TObject);
  2.  
  3. begin
  4.   Frame_Waren:=TFrame_Waren.Create(self);
  5.   Frame_CSI:=TFrame_CSI.Create(self);
  6.   Frame_BearbeiteDB:=TFrame_BearbeiteDB.Create(self);
  7.   Frame_Kalender:=TFrame_Kalender.Create(self);
  8.   Frame_News:=TFrame_News.Create(self);
  9. ...
  10.  
  11.  
  12. after this is done, I place them
  13.        Frame_CSI.Parent:=Panel_CSI;
  14.            Frame_CSI.Align:=alClient;

The last line is a tricky one.
Setting something at design-time at alClient may lead into severe troubles: Once one element exploded and covered all others.
It was really hard to get the ghost back into the bottle and get my software back.
if you use nested TPageControls it is not too easy to find out, which control exploded.

Sometimes I "must" set it to alNone because alClient kills the Frame-Layout. Not quite sure, why and how.
In no case the panel may be larger than its parent. This led to strange results. eg. buttons drifted to the edges.


CharlyTango

  • Full Member
  • ***
  • Posts: 148
Re: Layout problem by nested TPageControls
« Reply #9 on: June 20, 2025, 08:45:21 am »
in this cases i was advised not to use the common alClient, alNone etc and use the Anchor Editing instead.
Given the sheer number of possibilities, it's quite confusing at first and it was close to twisting my brain.

But after the shock moment, it offers completely different possibilities and is worth exploring at length.
I can well imagine that positioning with anchors also helps to fit a larger form into a smaller parent.

Just saw interesting Links regarding positioning, sizing and docking in another thread.

https://wiki.freepascal.org/Autosize_/_Layout
https://wiki.freepascal.org/Docking

seems to be some kind of nightmare ;-)


« Last Edit: June 20, 2025, 08:57:11 am by CharlyTango »
Lazarus stable, Win32/64

Nicole

  • Hero Member
  • *****
  • Posts: 1219
Re: Layout problem by nested TPageControls
« Reply #10 on: June 20, 2025, 09:51:59 pm »
There is an old film, which is called in German "What woman really want".
- you got it.

Since several days I use Lazarus 4 and love it everyday more. It has an own tab for anchors. In the past, I tried those anchors and gave up. WP works a lot with anchors. His code is perfect. But I could not use it, because every adaption of his demos ended in layout-destruction. Because I did not understand them.

Those links look promising. Perhaps I and the anchors will make friends this time. The Lazarus tile IDE is gorgeous. That a difference in working. Evidently, this is done by anchors.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11487
  • Debugger - SynEdit - and more
    • wiki
Re: Layout problem by nested TPageControls
« Reply #11 on: June 20, 2025, 10:29:38 pm »
Only half on topic, but you may consider also looking at child sizing.
https://lazarus-ccr.sourceforge.io/docs/lcl/controls/twincontrol.childsizing.html
https://lazarus-ccr.sourceforge.io/docs/lcl/controls/tchildcontrolresizestyle.html

Whenever you need something "grid like".

E.g. all the radios in the new watches property (display format) are done with that.

Mind you you can put a panel in the grid and sub-grid it.
Or anchor to something in the grid, and kind of get column spanning.


 

TinyPortal © 2005-2018