Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(Owner as TForm).Handle cause invalid type cast error

Status
Not open for further replies.

guscottg

Technical User
Mar 14, 2001
9
0
0
GB
I'm have Delphi 6 with all patches applied. I'm using the following code which I've taken from the Delphi 4 Unleashed book:

procedure TChildFrm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.WndParent := (Owner as TForm).Handle;
Params.Style := WS_CHILD or WS_CLIPSIBLINGS;
Params.X := 0;
Params.Y := 0;
end;

When I compile my application I receive the following error:

"Exception EInvalidCast in module xxxx at xxxxx. Invalid class subtype."

What I'm trying to do is to display a form inside a container like a TPageControl or a TPanel.
 
the exception you are getting is normal because the owner is not a form but a tpanel or Tpagecontrol.

to create a window inside a panel you can do this :

Code:
 formx:=TFormx.Create(Panel1);
 formx.ParentWindow:=Panel1.Handle;
 formx.Show;

or change the code in your CreateParams procedure like this :

Params.WndParent := (Owner as TWinControl).Handle;

cheers

--------------------------------------
What You See Is What You Get
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top