Solved

Create TWebBrowser at runtime.

Posted on 2004-04-13
9
1,966 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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