Solved

Create TWebBrowser at runtime.

Posted on 2004-04-13
9
1,916 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
  • 5
  • 3
9 Comments
 

Accepted Solution

by:
lnishimura earned 125 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
 

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now