Solved

Create TWebBrowser at runtime.

Posted on 2004-04-13
9
2,021 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 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
Independent Software Vendors: 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 160
Making delphi communicate with a c# service 16 138
Delphi problems to abort a printjob 9 51
Firemonkey how to swip panel with finger tap 1 42
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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