Anchors on a child form

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Anchors on a child form

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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Anchors on a child form

Giuliano Colla
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: [hidden email]

There you may obtain adequate assistance.

Giuliano


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Anchors on a child form

martin_wynne

> This appears to be a topic for the Lazarus list, as it appears that
> you're using the Lazarus LCL: [hidden email]
>
> There you may obtain adequate assistance.
>
> Giuliano

Thanks. Sorry for posting to the wrong list.

Martin.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Anchors on a child form

Mattias Gaertner
In reply to this post by martin_wynne
On Sun, 3 Jun 2018 13:06:59 +0100
Martin Wynne <[hidden email]> wrote:

> 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?

 

> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Anchors on a child form

martin_wynne
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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Anchors on a child form

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

> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal