Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create TWebBrowser at runtime.

Posted on 2004-04-13
9
Medium Priority
?
2,107 Views
Last Modified: 2008-02-07
Hi.

I need to create a TWebBrowser, at runtime.  I can do this without any problem, but I can't set the parent to be the form creating it.  (I need to be able to see it!)

I've never had this problem when creating components at runtime.

Thanks in advance,

MoonCalf.
0
Comment
Question by:MoonCalf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 

Accepted Solution

by:
lnishimura earned 500 total points
ID: 10814109
May This Help?


procedure TForm1.Button1Click(Sender: TObject);
var
 wb: TWebBrowser;
begin
  wb := TWebBrowser.Create(Form1);
  TWinControl(wb).Name := 'MyWebBrowser';
  TWinControl(wb).Parent := Form1;
  wb.Align := alClient;
  // TWinControl(wb).Parent := TabSheet1; ( To put it on a TabSheet )
  wb.Navigate('http://www.swissdelphicenter.ch');
end;
0
 
LVL 1

Author Comment

by:MoonCalf
ID: 10814126
Okay - I've done that now.

I just have one other issue with this (creating TWebBrowser at runtime) - I can't set align=alClient.

Well, I can, it just doesn't work.

Put this in a button click event to see what I've got so far....

    wbOutput:=TWebBrowser.Create(AOwner);
    wbOutput.ParentWindow:=TWinControl(Owner).Handle;
    wbOutput.Align:=alClient;
    wbOutput.Navigate('http://www.google.co.uk');

Any advice?

Thanks,

MoonCalf.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10814227
This works for me! The Align works fine!

Shane

procedure TForm1.FormActivate(Sender: TObject);
var
 WB: TWebBrowser;
begin
 WB:= TWebBrowser.Create(Form1);
 TWinControl(wb).Parent := Form1;
 WB.Align:= alCLient;
 WB.Navigate('http://www.google.co.uk');
end;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:lnishimura
ID: 10814268
and if you use
 

 wboutput.Height:=form1.Height;
 wboutput.Width:=form1.Width;

It will use the all form///

0
 

Expert Comment

by:lnishimura
ID: 10814292
Actually its working for me too
0
 
LVL 1

Author Comment

by:MoonCalf
ID: 10814369
Okay - I can see where my visibility problem was before, but I still can't get align to work.  Thanks for the code inishimura, but try putting that exact code in the FormCreate event.  The align=alClient doesn't work.


procedure TForm1.FormCreate(Sender: TObject);
var
  wbOutput  : TWebBrowser;
begin
  wbOutput:=TWebBrowser.Create(Self);
  wbOutput.ParentWindow:=Self.Handle;
  wbOutput.Align:=alClient;
  wbOutput.Navigate('http://www.google.co.uk');
end;


MoonCalf.
0
 

Expert Comment

by:lnishimura
ID: 10814391
USE this
TWinControl(wb).Parent := Form1;

need to define a Parent to Aling to
 

if dont...how can it use all client????
0
 
LVL 1

Author Comment

by:MoonCalf
ID: 10814426
Thanks for the help everyone.

Don't get why setting ParentWindow=Form1.Handle should be different from Parent=Form1, but apparently it is.

Ah well - you live and learn.

MoonCalf.
0
 

Expert Comment

by:lnishimura
ID: 10814466
This Worked Fine for me...

procedure TForm1.FormCreate(Sender: TObject);
var
  wbOutput  : TWebBrowser;
begin
  wbOutput:=TWebBrowser.Create(self);
  wbOutput.ParentWindow:=self.Handle;
  TWinControl(wboutput).Parent := Form1;
  wbOutput.Align:=alClient;
  wbOutput.Navigate('http://www.google.co.uk');
  end;
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question