Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using WebBrowser and PageProducer? 1

Status
Not open for further replies.

Punchinello

Programmer
Apr 25, 2003
116
US
I am using a webbrowser to open a local html file. No problem. But now I want to replace text in the html file with field values from a database so where the html file might include "Company Name: <#CompName>" I want to replace the <#CompName> tag with the value from a dataset. Sometimes it will be straight from a field in the dataset, but other times it will be a string constructed from one or more fields (like city, state zip). Also, a single page may need fields from multiple datasets.

I'm using the webbrowser for read-only display purposes only and not on the web or with webservices. I've looked at the PageProducer and the DataSetPageProducer but they seem to provide a different kind of thing.

Any ideas would be appreciated?
 
My solution was to place code in the OnDocumentComplete event that exchanges custom tags in the html code with values from a dataset. So the html file might look like this:
Code:
<html>
  <body>
    <p>Customer Name: <#CUST_NAME></p>
  </body>
</html>
When the delphi program navigates to this file, the OnDocumentComplete event is used to resolve the <#..> tags to values. Here's the code:
Code:
procedure TDatabaseForm.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
var
  document: IHTMLDocument2;
  S: String;
begin
  document := WebBrowser1.Document as IHTMLDocument2;
  S := document.body.innerHTML;
  S := AnsiReplaceStr(S, '<#CUST_NAME>', Table1.FieldByName('CUST_NAME').DisplayText);
  document.body.innerHTML := S;
end;
I'm new to working with html so if any of you web-gurus out there have opinions - either [mad] or [thumbsup2] - it will help me to be confident with this solution before I migrate it through this application.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top