Add component in run-time

Hi!

I already know how to add a simple label in runtime, but I haven't managed how to add a TWEBBROWSER one.

Help me (F1...F1 :)) )

LVL 1
jpcsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
HI,
this should work:

procedure TForm1.Button1click (Sender : TObject);
var
 WebBrowser1 : TWebBrowser;
begin
 WebBrowser1 := TWebBrowser.Create(Self);
 panel1.insertcontrol(Webbrowser);
  WebBrowser.Align := alClient;
end;

Regards Barry
0
intheCommented:
note:
 add SHDocVw_TLB to the uses section;

and could do
TWinControl(WebBrowser1).Parent := Form1;
instead of putting in panel ..
0
jpcsAuthor Commented:
Thanks Barry, but before I accept your answer, I need you to answer me this :

I used the webbrowser1.free before I create it (I made the test so that I know it exists), and it works fine... It removes the old one and add a new one, but there is a BIG problem... I'm using WinNT and my task manager indicates that it uses more and more memory. Shouldn't free release the memory and the create use the memory left by the old tbrpwser component?


Please help me on this, because is too important.


thanks

Joao
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

intheCommented:
Hi,
ill have a look ,
i seen your other question about the memory and had a search but i never heard of anyone having memory problems before using twebbrowser.
i make a demo of just creating and destroying a twebbrowser several times..
and see what it does.
back later ;-)

0
jpcsAuthor Commented:
Thanks... By the way... the other question is mine :))

thanks
0
intheCommented:
i make a demo:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
   ShDocvw_tlb, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Panel1: TPanel;
    Edit1: TEdit;
    OpenDialog1: TOpenDialog;
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  webbrowser : twebbrowser;
implementation

{$R *.DFM}

procedure TForm1.Button3Click(Sender: TObject);
begin
if assigned(webbrowser)
then begin
opendialog1.execute;
 webbrowser.OleObject.navigate(opendialog1.filename);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser := TWebBrowser.Create(self);
TWinControl(WebBrowser).Parent := Panel1; // or whatever
WebBrowser.Align := alClient;
button2.enabled:=true;
button1.enabled:=false;
button3.enabled := true;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if assigned(webbrowser)
 then begin
 webbrowser.Application_._Release;
 webbrowser.FreeOnRelease;
 webbrowser.Free;
 button1.enabled:=true;
 button2.enabled:=false;
 buton3.enabled := false;
 end;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (key = #13) then begin
if assigned(webbrowser) then
webbrowser.OleObject.navigate(edit1.text);
end
else key := #0;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
button1.enabled := true;
button2.enabled := false;
button3.enabled := false;
end;

end.




and i use another demo using global memory status to check the memory and also made a program to check the system resources.


here is the memory program:

unit GlobalMemoryStatusU;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TGlobalMemoryStatusForm = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    ButtonGlobalMemoryStatus: TButton;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    procedure ButtonGlobalMemoryStatusClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  GlobalMemoryStatusForm: TGlobalMemoryStatusForm;

implementation

{$R *.DFM}

procedure TGlobalMemoryStatusForm.ButtonGlobalMemoryStatusClick(
  Sender: TObject);
var
  GlobalMemoryInfo : TMemoryStatus;  // holds the global memory status information
begin
  {set the size of the structure before the call.}
  GlobalMemoryInfo.dwLength := SizeOf(GlobalMemoryInfo);

  {retrieve the global memory status...}
  GlobalMemoryStatus(GlobalMemoryInfo);

  {and display the information}
  Label1.caption := 'Results of GlobalMemoryStatus:';
  Label2.caption := 'Record structure size: '+IntToStr(
                     GlobalMemoryInfo.dwLength)+' bytes';
  Label3.caption := 'Current memory load: '+IntToStr(
                     GlobalMemoryInfo.dwMemoryLoad)+'%';
  Label4.caption := 'Total physical memory: '+Format('%.0n',[
                     GlobalMemoryInfo.dwTotalPhys/1])+' bytes';
  Label5.caption := 'Total available physical memory: '+Format('%.0n',[
                     GlobalMemoryInfo.dwAvailPhys/1])+' bytes';
  Label6.caption := 'Total paging file size: '+Format('%.0n',[
                     GlobalMemoryInfo.dwTotalPageFile/1])+' bytes';
  Label7.Caption := 'Total available paging file memory: '+Format('%.0n',[
                     GlobalMemoryInfo.dwAvailPageFile/1])+' bytes';
  Label8.caption := 'Total virtual memory: '+Format('%.0n',[
                     GlobalMemoryInfo.dwTotalVirtual/1])+' bytes';
  Label9.caption := 'Total available virtual memory: '+Format('%.0n',[
                     GlobalMemoryInfo.dwAvailVirtual/1])+' bytes';
end;

end.



after plenty of testing ,i see no problems with memory or system resources program .everything seems fine.
0
jpcsAuthor Commented:
Well... The problem persists... I can't understand... Can you use Taskmanager Process Viewer from Windows NT?

I'll explain step by step my problem.


I run the application
Memory Usage = 2996k

Button1 Press
Memory Usage = 3020k

Button3 press (opens experts-exchange page)
Memory Usage = 7268k

Button2 Press (Shouldn't it go back to 2996k???)
Memory Usage = 7148k

-------- First Webbrowser window -----

Button1 Press
Memory Usage = 7148k

Button3 Press
Memory Usage = 7484k

Button2 Press
Memory Usage = 7300k

-------- Second Webbrowser Window -----

Button 1 Press
Memory Usage = 7300k

Button 3 Press
Memory Usage = 7640k

Button 2 Press
Memory Usage = 7488k

---- And so on... ----


As you see, the memory isn't totally free.

Am I doing anything wrong?
0
intheCommented:
what happens when you close the app completely?
is all memory back to normal?
i can have a look on nt in a while so i see then.

0
jpcsAuthor Commented:
Yes.. It comes all back to normal


Regards
0
intheCommented:
why you reject my answer?
the reason your rejecting relates directly to this question:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10271223 

your question asked how to create at runtime a twebbrowser and i have gave the answer .this is not very fair becuase i dont know the memory problem answer yet.

anyway i go to nt and try and yes i see what you mean ,the memory usage only goes up ,yet the nt performance moniter seems ok.
i will look some more later at why.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jpcsAuthor Commented:
I did?

I'm very sorry... It wasn't my intend. Maybe I click enter when I shouldn't. I'm really sorry.

Don't worry, because the points will be yours.


Just Hope you can solve the memory problem. If you do, I'll give you 100 extra points, OK?

Thanks
0
jpcsAuthor Commented:
Sorry for the rejection. It was a mistake


Regards

Joao
0
DrDelphiCommented:
I agree with inthe... the original question is asked and answered, the memory issue was aside. He deserves the points for the answer.
0
intheCommented:
thankyou ,i am looking into memory problem as i type ,will update when find anything.
0
jpcsAuthor Commented:
I know Dr Delphi, but as I quoted before, it was a mistake... Its fixed now!

regards
0
DrDelphiCommented:
Sorry... didn't mean to beat a dead horse. You accepted his answer at the same time I posted my commment.
0
jpcsAuthor Commented:
It's OK Dr. Delphi!

OK, Thanks inthe
0
DrDelphiCommented:
<G>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.