LeTay
asked on
Put data in a TWebBrowser component of Delphi
How can I put data in a TWebBrowser component "directly"
I mean, i have some html data in a "string".
How can i show it in that component without using the navigate method ?
Thanks
I mean, i have some html data in a "string".
How can i show it in that component without using the navigate method ?
Thanks
ASKER
Okay if it is a file
But if it is from a string variable (data comes from database) ?
Is a temporary file necessary ?
But if it is from a string variable (data comes from database) ?
Is a temporary file necessary ?
> But if it is from a string variable (data comes from database) ?
> Is a temporary file necessary ?
Not it is not necessary. You missed the other half of the comment.
"To load from string variable, there is an example at About.com."
> Is a temporary file necessary ?
Not it is not necessary. You missed the other half of the comment.
"To load from string variable, there is an example at About.com."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There's a good and detailed article about customizing TWebBrowser here: http://delphidabbler.com/articles?article=14.
ASKER
Sorry ...
Forget to mention you need to include ActiveX in the uses clause.
Complete code:
Complete code:
Uses ActiveX;
procedure WBLoadHTML(WebBrowser: TWebBrowser; HTMLCode: string) ;
var
sl: TStringList;
ms: TMemoryStream;
begin
WebBrowser.Navigate('about:blank') ;
while WebBrowser.ReadyState < READYSTATE_INTERACTIVE do
Application.ProcessMessages;
if Assigned(WebBrowser.Document) then
begin
sl := TStringList.Create;
try
ms := TMemoryStream.Create;
try
sl.Text := HTMLCode;
sl.SaveToStream(ms) ;
ms.Seek(0, 0) ;
(WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms)) ;
finally
ms.Free;
end;
finally
sl.Free;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject) ; // or at ButtonClick
var
sHTML : string;
begin
{sHTML := '<a href="http://delphi.about.com">GOTO</a'+
'<b>About Delphi Programming</b>';}
sHTML:= <<Load you data from DB or any other source.
WBLoadHTML(WebBrowser1, sHTML) ;
end;
Open in new window
To load from string variable, there is an example at About.com.