delphi webbrowser copy text from website
<p>In my application I want to copy all the text from a website into a string variable. Because of some issues with Indy, I want to use the webbrowser component.</p>

<p>The following code works perfectly for me:</p>

<pre><code>procedure TForm1.Button1Click(Sender: TObject);
begin
  WebBrowser1.Navigate('www.tribalwars.nl');
  while WebBrowser1.Busy do
    Application.ProcessMessages;
  Memo1.Lines.Add((WebBrowser1.Document as IHTMLDocument2).body.innerText);
end;
</code></pre>

<p>However, in the example above I use a WebBrowser that has been manually created on my Form1.
Now I want to create it during runtime. I tried the following code:</p>

<pre><code>procedure TForm1.Button2Click(Sender: TObject);
var Web: TWebBrowser;
begin
  Web := TWebBrowser.Create(nil);
  Web.Navigate('www.tribalwars.nl');
  while Web.Busy do
    Application.ProcessMessages;
  Memo1.Lines.Add((Web.Document as IHTMLDocument2).body.innerText); //This line raises the error mentioned below
  Web.Free;
end;
</code></pre>

<p>Unfortunately it keeps raising the following error: </p>

<p>Project Project1.exe raised exception class $C0000005 with message 'access violation at 0x005d9b4f: read of address 0x00000000'.</p>

<p>I guess I'm trying to use something that hasn't been created yet, or somewhere in that direction.
I hope someone can help me get this to work!</p>

<p>EDIT: whosrdaddy mentioned that I should make this component visible. How can I do that? I tried this, but it doesn't work:</p>

<pre><code>procedure TForm1.Button2Click(Sender: TObject);
var Web: TWebBrowser;
begin
  Web := TWebBrowser.Create(nil);
  Web.Left := 50;
  Web.Top := 50;
  Web.Width := 50;
  Web.Height := 50;
  Web.Visible := True;

  Application.ProcessMessages;
  Web.Navigate('www.tribalwars.nl');
  while Web.Busy do
    Application.ProcessMessages;
  Memo1.Lines.Add((Web.Document as IHTMLDocument2).body.innerText);
  Web.Free;
end;
</code></pre>