Board index » delphi » Form Parent/Show problem

Form Parent/Show problem

Hopefully a simple one:

I want a floating form that stays on top of my main form (SDI), but is non-
modal, a la Find dialog in Word.  A VB coder said that he did this just by
calling Show on the form and setting the form's parent to the main form.

So I tried:

        frmDebug := TfrmInlineDebug.Create(Application.MainForm);
        frmDebug.Parent  := Application.MainForm;
        frmDebug.Visible := true;

The frmDebug.Visible line raises an exception EInvalidOperation with message
"Cannot focus a disabled or invisible window".

Why am I getting this error?  Also, is this the right way to achieve the
effect I want?

Thanks in advance.

 

Re:Form Parent/Show problem


John,

The proper way to do this is:
1. Make sure frmDebug is not "AutoCreated". Go to "Project->Options(Forms
Tab)". Your Main Form should be the only Form in the Auto Create List.

2. In the Object Inspector, set frmDebug's FormStyle Property to
"fsStayOnTop".

3. In frmDebug's OnClose Event:
procedure TfrmInlineDebug.FormClose(Sender: TObject; var Action:
TCloseAction);
begin
  Action := caFree;
end;
This will cause the Form to Free itself no matter how it is closed.

4.Finally, your Creation code.
...
  frmDebug := TfrmInlineDebug.Create(self);{or Application.MainForm}
  frmDebug.Show;
...

5. Never ask a VB Coder how to write proper Delphi code ;>)

Good Luck!
Gregg

Re:Form Parent/Show problem


In article <9046951A8johncceuroplacerc...@192.168.1.99>, John Carlyle-Clarke
wrote:

Quote
> I want a floating form that stays on top of my main form (SDI), but is non-
> modal, a la Find dialog in Word.  A VB coder said that he did this just by
> calling Show on the form and setting the form's parent to the main form.

Using a stay-on-top form like Gregg suggests would do, but i like to clear up
the confusion about the forms parent: the VB coder is not talking about the
same kind of parent the Parent property in a Delphi control represents. To set
the parent the way he did it you have to override the CreateParams method of
the form, like this:

 procedure TForm2.CreateParams(var Params: TCreateParams);
 begin
   inherited;
   Params.WndParent := Application.mainform.handle;
 end;

This sets the API parent, which determines relative Z order. The Delphi Parent
property does something more: it turns the form into a true child window (a
control) and as such it is limited to the client area of its parent window.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Re:Form Parent/Show problem


100113.1...@compuXXserve.com (Peter Below (TeamB)) wrote in
<VA.00006937.0078d...@antispam.compuserve.com>:

Quote

>Using a stay-on-top form like Gregg suggests would do, but i like to clear up
>the confusion about the forms parent: the VB coder is not talking about the
>same kind of parent the Parent property in a Delphi control represents. To set
>the parent the way he did it you have to override the CreateParams method of
>the form, like this:

> procedure TForm2.CreateParams(var Params: TCreateParams);
> begin
>   inherited;
>   Params.WndParent := Application.mainform.handle;
> end;

>This sets the API parent, which determines relative Z order. The Delphi Parent
>property does something more: it turns the form into a true child window (a
>control) and as such it is limited to the client area of its parent window.

Thanks for this!  I thought from reading the Delphi docs that the parent
property was not the same as the Windows "parent window", but I was not 100%
sure, nor did I know how to access this other property, so this is a huge help.  
I wanted to avoid stay-on-top forms specifically.  Thanks to Gregg for the
advice on form lifetime too.

Other Threads