Board index » delphi » Two questions about MDI forms!

Two questions about MDI forms!

Hi!

1)
I am using MDI forms like FormX=TFormY.Create. TFormY is already set
to be MDI form. Delphi raises an Exception 'No MDI parent active!'. I
don't know how to set it to be active. It is on screen and even if I
do SetFocus Active proprety of ParentForm doesn't change.
(Parent Form isn't active at startup, I do ParentForm.Show)

2) How to eliminate visible resizing of MDIClient form when creating
it (I want it to be maximized when it is created). MDIClient form is
first showed in its original size and then resized, what is really
annoying. (I think Microsoft Word doesn't do that resizing)
--------------------------------------------------------
 Name   : Mitja Perko
 E-Mail : Mitja.Pe...@guest.arnes.si
 WWW    : http://www2.arnes.si/guest/osljbk1/index.html
--------------------------------------------------------

 

Re:Two questions about MDI forms!


Quote
>Hi!

>1)
>I am using MDI forms like FormX=TFormY.Create. TFormY is already set
>to be MDI form. Delphi raises an Exception 'No MDI parent active!'. I
>don't know how to set it to be active. It is on screen and even if I
>do SetFocus Active proprety of ParentForm doesn't change.
>(Parent Form isn't active at startup, I do ParentForm.Show)

don't forget to set:
  (MainForm as TForm).FormStyle:= fsMDIForm;
:-D

Quote

>2) How to eliminate visible resizing of MDIClient form when creating
>it (I want it to be maximized when it is created). MDIClient form is
>first showed in its original size and then resized, what is really
>annoying. (I think Microsoft Word doesn't do that resizing)

sorry i have no time to debug all Forms-Unit. But you can do it,
than please reply me on condition you've got it.

ian's revision.

---
.oooO           `sibi imperare maximum imperium est!`             Oooo.
(   )         i...@integrator.lviv.ua; i...@trasa.lviv.ua           (   )
 \ (                  tel/fax: +380+322+214085                     ) /
  \_) Markiyan Kychma, Dovgenko str. 14/48, Lviv, 290066, Ukraine (_/

Re:Two questions about MDI forms!


In article <5uuadd$9g...@kanja.arnes.si>, Mitja Perko
<Mitja.Pe...@guest.arnes.si> writes

Quote
>Hi!

>1)
>I am using MDI forms like FormX=TFormY.Create. TFormY is already set
>to be MDI form. Delphi raises an Exception 'No MDI parent active!'. I
>don't know how to set it to be active. It is on screen and even if I
>do SetFocus Active proprety of ParentForm doesn't change.
>(Parent Form isn't active at startup, I do ParentForm.Show)

The MainForm of the application should be an MDI parent form
(FormStyle:=fsMDIForm) and it must be created before any child forms or
you will receive that exception.

Quote
>2) How to eliminate visible resizing of MDIClient form when creating
>it (I want it to be maximized when it is created). MDIClient form is
>first showed in its original size and then resized, what is really
>annoying. (I think Microsoft Word doesn't do that resizing)
>--------------------------------------------------------

Default windows behaviour I think

Quote
> Name  : Mitja Perko
> E-Mail        : Mitja.Pe...@guest.arnes.si
> WWW   : http://www2.arnes.si/guest/osljbk1/index.html
>--------------------------------------------------------

Kind Regards
Claire, c...@HallworthHome.demon.co.uk

Re:Two questions about MDI forms!


Quote
Mitja Perko wrote:

> Hi!

> 1)
> I am using MDI forms like FormX=TFormY.Create. TFormY is already set
> to be MDI form. Delphi raises an Exception 'No MDI parent active!'. I
> don't know how to set it to be active. It is on screen and even if I
> do SetFocus Active proprety of ParentForm doesn't change.
> (Parent Form isn't active at startup, I do ParentForm.Show)

> 2) How to eliminate visible resizing of MDIClient form when creating
> it (I want it to be maximized when it is created). MDIClient form is
> first showed in its original size and then resized, what is really
> annoying. (I think Microsoft Word doesn't do that resizing)
> --------------------------------------------------------
>  Name   : Mitja Perko
>  E-Mail : Mitja.Pe...@guest.arnes.si
>  WWW    : http://www2.arnes.si/guest/osljbk1/index.html
> --------------------------------------------------------

Hi, Mitja;

re: your questions, here is my 'two cents' worth:

1) I can't see that you're doing anything out of the ordinary, unless
you are issuing the 'ParentForm.Show immediately before the Create Child
code. I have only ever created children by taking action on the parent
form. I have noticed, though, that if I change the active form in code,
things don't do what I think they should unless I issue
'Application.ProcessMessages' after the activate instruction and other
critical instructions. You might want to try this.

2) There is a property listed in the Object Inspector called
'WindowState', which can be set to Normal, Minimized, or Maximized. This
may do the trick (no guarantee).

If you don't mind I have a question of my own. I have a parent form with
two children. I am trying to take the contents of a listbox on the first
child to a memo on the second. There seems to be _no way_ to reference
components on a form using the ActiveMDIChild or MDIChildren functions;
these appear to be restricted to properties of the form _only_. Any
suggestions?

As an alternative I could use the SendMessage function, but for one
small problem: SendMessage expects a LongInt for wParam, but the memory
location variable is a pointer. Any ideas on how to convert pointers to
LongInt?

Re:Two questions about MDI forms!


I think you are trying to create an MDI child without having an MDI parent.

To create MDI children, you must have a form that is active and its
formstyle property must be MDIForm

Re:Two questions about MDI forms!


Quote
Mitja.Pe...@guest.arnes.si (Mitja Perko) wrote:
>2) How to eliminate visible resizing of MDIClient form when creating
>it (I want it to be maximized when it is created). MDIClient form is
>first showed in its original size and then resized, what is really
>annoying. (I think Microsoft Word doesn't do that resizing)

Take a look at the CreateParams method, and the TCreateParams
structure. I think you'll have to look into the VCL source code,
however, since they're not documented in the help files.......

You can set the size and position of the window at time of its
creation.

Got the tip from the wonderful book "Delphi Programming Problem
Solver" by Neil Rubenking. Has tons of intermediate to advanced "how
to do this" type of solutions, and it's worth every cent of its cost!

HTH
Marc

Re:Two questions about MDI forms!


Adrian Berry <so...@interlog.com> wrote in article <341D5B09.6...@interlog.com>...

<snip>

Quote
> Mitja Perko wrote:
> If you don't mind I have a question of my own. I have a parent form with
> two children. I am trying to take the contents of a listbox on the first
> child to a memo on the second. There seems to be _no way_ to reference
> components on a form using the ActiveMDIChild or MDIChildren functions;
> these appear to be restricted to properties of the form _only_. Any
> suggestions?

> As an alternative I could use the SendMessage function, but for one
> small problem: SendMessage expects a LongInt for wParam, but the memory
> location variable is a pointer. Any ideas on how to convert pointers to
> LongInt?

The key to remember is that activemdichild and mdichildren return results of type TForm.
The base TForm has no components defined.  However, your program's derived form type
does.  Typecast as follows:

mychild:=mymainform.activemdichild as Tmychildformtype

and mychild will 'see' the components.

--
That's my 2 (adjusted for inflation)

Other Threads