Solved

HTML Rendering without needing the source written to a file.

Posted on 2004-03-30
10
497 Views
Last Modified: 2010-04-05
Hi,

I'm looking for a quick and easy way to render html code that doesn't need to me actually have the code saved in a file. The IE wrapper component doesn't seem to be able to do this and the htmlayout component/engine seems to actually be missing more of the S outta the SDK, (By which I mean they don't actually distribute any source except the example apps, as far as I can see), and I'm not sure whether it can do this or not. Any ideas on how to manage this?

Otherwise, what would be the best way to manage this?

I'd prefer not to have it stored in a file as the code would be being edited (although not quite literally on the fly)

Incidentally, I'm using Delphi7.
0
Comment
Question by:marajin
[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
  • 5
10 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 250 total points
ID: 10718585
The IE wrapper can do this for you....

// Procedure to load you browser component using text
procedure LoadHtml(Browser: TWebBrowser; Html: String);
var
  V, vDocument, vMIMEType, vHTML: OleVariant;
begin

  if Assigned(Browser) then
  begin
     Browser.Stop;
     V:=Browser.Document;
     if (VarType(V) = varDispatch) then
     begin
        vDocument:=V.Script.Document;
        vMIMEType:='text/html';
        vHTML:=Html;
        vDocument.Open(vMIMEType);
        vDocument.Clear;
        vDocument.Write(vHTML);
        vDocument.Close;
     end;
  end;

end;

// Example usage
procedure TForm1.Button1Click(Sender: TObject);
begin

  LoadHtml(WebBrowser1, '<html>This is a test</html>');

end;

------------

Regards,
Russell

0
 

Author Comment

by:marajin
ID: 10720090
Well... I do feel the idiot...

But fair enough, you pointed out the way and your code works perfectly, so the points go to you :)

Thanks!
0
 

Author Comment

by:marajin
ID: 10722843
A quick additional if you don't mind...

The webbrowser grabs focus if you click on it (Unsurprisingly), however if you go back to the code editor and hit a couple of keys, all keys after the first will be intercepted by the browser.

That is to say, if for example I scroll down the page in the browser, then go back to my editor and type "wibble" in, W gets put in the code but all after that is sent to the browser instead of my code editor.
0
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!

 
LVL 26

Expert Comment

by:Russell Libby
ID: 10723862

It most likely has to do with what you are loading, as I can't reproduce the problem that you are having.

If you could show me the html code that produces this behavior (just enough so that the behavior is displayed would be fine) then I would be willing to take a look at it for you.

Regards,
Russell
 
0
 

Author Comment

by:marajin
ID: 10724565
I don't think it's my HTML code, as it occurs with any of a number of totally different pages.

It's much more likely to do with the way I've laid out the WebBrowser and code editor. They both sit on a single MDI child, seperated by a splitter. I'm currently feeding the browser the updated document with the editor's OnChange event. Less than the best way to do it, I know, but I wanted to see how it handled effective "realtime" modification.

I can pin down what causes the issue, but not what relieves it. Any form of action towards the web browser will cause it to keep stealing the keyboard input, but sometimes it seems to give up and leaves the editor to take the keyboard input. The most repeatable way of making the browser relinquish control is to scroll the editor up and down a bit then select a point in the text/code. This only works sometimes however.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10725451
Thanks for the explanation, makes much more sense now... (OnChange firing)

And it is, to some degree, html dependant. By that I mean that the display has some kind of input field/button/etc control in it. If the display is just a textual rendering then this does not happen (thus I wasn't able to reproduce at first).
Regardless, the following should resolve your problem; let me know if it does not.

Russell

-------

procedure LoadHtml(Browser: TWebBrowser; Html: String);
var
  V, vDocument, vMIMEType, vHTML: OleVariant;
  hwndActive:    HWND;
begin

  hwndActive:=GetFocus;
  if Assigned(Browser) then
  begin
     Browser.Stop;
     V:=Browser.Document;
     if (VarType(V) = varDispatch) then
     begin
        vDocument:=V.Script.Document;
        vMIMEType:='text/html';
        vHTML:=Html;
        vDocument.Open(vMIMEType);
        vDocument.Clear;
        vDocument.Write(vHTML);
        vDocument.Close;
     end;
  end;
  SetFocus(hwndActive);

end;


0
 

Author Comment

by:marajin
ID: 10725577
It won't even compile, telling me that it's passing too many parameters to SetFocus. Do I need to include an additional unit to get an overloaded procedure?
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10725602

What version of Delphi are you using, and have you declared this procedure as part of the form? Basically it boils down to a namespace conflict, as TWinContols have a SetFocus method associated with them, when what you are after is the windows api SetFocus.

So change the line to the full namespace qualification

Windows.SetFocus(hwndActive);

----

Russell
0
 

Author Comment

by:marajin
ID: 10725632
Ok :) That works great now as far as I can tell, thanks.

But by the by, I'm using Delphi 7, and the procedure is delared as part of the form yes.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10725643
Namespace conflict, simple name resolution is all that was needed...

Let me know if you have further problems (regarding the focus ;-),
Russell
0

Featured Post

Technology Partners: 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
Help on project with Soap 10 69
can't find the executable in Simulator 1 129
shape, triangle, dbctrlgrid 3 46
Add New Database Table in database file using delphi 3 54
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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