Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2018-06

Anchors on a child form

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Wynne
If I create a child form by setting Parent:=other_form; in FormCreate,
it cannot be dragged to a new position by the user.

If I then remove the top and left anchors by setting Anchors:=[]; in FormCreate (or in the Object Inspector) so that it can be dragged, I get this exception:

'TWinControl.WMSize loop detected, the widgetset does not like the LCL bounds or sends unneeded wmsize messages'.

I have tried setting

Windows.SetParent(Handle,other_form.Handle); (instead of
Parent:=other_form;)

which removes the exception, but the child form then retains focus after use, preventing the parent form from responding to the keyboard (which defeats the object of using a child form in the first place).

I'm porting a project to Lazarus from Delphi5, where it works fine. Child forms can be dragged around even with the top and left anchors set.

Thanks for any help in fixing this.

Martin.

Reply by email

Giuliano Colla
to Martin Wynne

Il 03/06/2018 14:06, Martin Wynne ha scritto:

I'm porting a project to Lazarus from Delphi5, where it works fine. Child forms can be dragged around even with the top and left anchors set. Thanks for any help in fixing this

This appears to be a topic for the Lazarus list, as it appears that you're using the Lazarus LCL:

There you may obtain adequate assistance.

Giuliano

Reply by email

Martin Wynne
to Giuliano Colla
Show quoted text 6 lines
This appears to be a topic for the Lazarus list, as it appears that you're using the Lazarus LCL: There you may obtain adequate assistance. Giuliano

Thanks. Sorry for posting to the wrong list.

Martin.

Reply by email

Mattias Gaertner
to Martin Wynne: If I create a child form by setting Parent:=other_form; in FormCreate, it cannot be…
If I create a child form by setting Parent:=other_form; in FormCreate, it cannot be dragged to a new position by the user.

Correct. Setting aForm.Parent makes the form a "normal" control like a frame or panel. If you want dragging, you need to do the same as for any other LCL control:
http://wiki.freepascal.org/LCL_Drag_Drop

If I then remove the top and left anchors by setting Anchors:=[]; in FormCreate (or in the Object Inspector) so that it can be dragged, I get this exception:

Removing anchors won't give you dragging. It centers a control on its parent client area.

'TWinControl.WMSize loop detected, the widgetset does not like the LCL bounds or sends unneeded wmsize messages'.

Can you create a bug report with an example to reproduce the loop?

Show quoted text 11 lines
I have tried setting Windows.SetParent(Handle,other_form.Handle); (instead of Parent:=other_form;) which removes the exception, but the child form then retains focus after use, preventing the parent form from responding to the keyboard (which defeats the object of using a child form in the first place). I'm porting a project to Lazarus from Delphi5, where it works fine. Child forms can be dragged around even with the top and left anchors set.

Can you give more details, what the Delphi program does?

Mattias

Reply by email

Martin Wynne
to Mattias Gaertner

Hi Mattias,

Thanks for your reply.

> 'TWinControl.WMSize loop detected, the widgetset does not like the LCL > bounds or sends unneeded wmsize messages'. Can you create a bug report with an example to reproduce the loop?

Sorry, I don't know how to do that. However, it is very easy to replicate:

1. start a new project application.
2. add an additional new form.
3. in Form2 add:

uses Unit1;
procedure TForm2.FormCreate(Sender: TObject);
begin
   Parent:=Form1;
   Anchors:=[];
   Visible:=True;
end;

4. run it, and the debugger will show the error message.

Can you give more details, what the Delphi program does?

In Delphi5 setting Parent:=Form1 causes Form2 to behave very similarly to a TPanel with the addition of some form properties. It has a top caption bar by means of which it can be dragged around on Form1, a red X to dismiss it, and it can be resized by dragging the edges/corners.

But it never gains focus or an "Active" border. Focus remains with Form1 at all times. If there are underlined keyboard accelerator keys on its controls, they are merged with any on Form1 and on any other child forms.

For a graphical drawing program it makes a very useful floating toolbox which the user can drag around and/or resize to avoid obscuring the drawing. My application uses several of them, some quite large which wouldn't fit into a top toolbar.

In Lazarus it initially looks similar, but can't be dragged around and behaves strangely if resized. I hoped to cure that by removing the anchors, but then got the error message above.

It can be cured by using Windows.SetParent instead of Parent:=, but now the child form gains focus and an Active border whenever it is dragged or its controls are clicked. Which is a nuisance for the user because the parent form loses focus and the expected keyboard shortcuts no longer work until the parent form is clicked.

Thanks for any help.

Martin.

Reply by email

Giuliano Colla
to Martin Wynne

Il 04/06/2018 14:06, Martin Wynne ha scritto:

Show quoted text 10 lines
uses Unit1; procedure TForm2.FormCreate(Sender: TObject); begin   Parent:=Form1;   Anchors:=[];   Visible:=True; end; 4. run it, and the debugger will show the error message.

Just remove the two lines

Parent:= Form1; (which is wrong, because it makes Form2 a widget inside
Form1)

and

Anchors:=[]; (which is useless)

And it will work.

Giuliano

Reply by email