Solved

Create TWebBrowser at runtime.

Posted on 2004-04-13
9
1,939 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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