Jump to content
Sign in to follow this  
scienceguy

Delphi WebBrowser Display Problem

Recommended Posts

Dear all,

 

I have a problem with the display of HTML code in the Delphi Webbrowser.

 

Following problem:

If I write html code that includes an image, then the image is not displayed in Delphi, I only see a cross. But the html file is being displayed correctly in a normal browser.

However, If I use a website like WordToHtml Converter, and take that html code, than the image is displayed correctly in Delphi. Both Html codes are identical, with the difference that the source of the image is then coming from that converter website.. I do not really  understand what the problem is. The formatting is displayed correctly.

 

My Delphi code to display html code looks like this:

 

// Load HTML File and Display it in WBBROWSER
procedure TForm1.LoadHtmlCode(var filename:string);
//https://stackoverflow.com/questions/41957051/how-to-change-font-in-twebbrowser
VAR
   Doc: Variant;
   htmlcode:string;

   textfile2:TextFile; // html file
   temp:string;

begin

    // Load Htmlcode from File

    // init
    htmlcode:='';

    AssignFile(textfile2, filename);
    reset(textfile2);

    while not eof(textfile2) do
    begin
          readln(textfile2, temp);
          htmlcode:=htmlcode+temp;
    end;

    CloseFile(textfile2);


    if NOT Assigned(wbBrowser.Document) then
        wbBrowser.Navigate('about:blank');

    // Display HTML Code
    Doc := wbBrowser.Document;
    Doc.Clear;
    Doc.Write(htmlcode);
    Doc.Close;
    Doc.DesignMode := 'Off';

    WHILE wbBrowser.ReadyState < READYSTATE_INTERACTIVE
    DO Application.ProcessMessages;

    doc.body.style.fontFamily:='Arial';
    wbBrowser.OleObject.Document.bgColor := '#000000';
end;

 

And my simple HTML code:

<!DOCTYPE html>

<html>

<body>


<p style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm;margin-left:0cm;line-height:107%;font-size:15px;font-family:"Calibri",sans-serif;text-align:justify;'><span data-darkreader-inline-color="" style="font-size: 29px; line-height: 107%; font-family: Corbert; color: white; --darkreader-inline-color: #e8e6e3;">blablabla.</span></p>

<img src="img/Antenne.png" height="80" width="50">
  
</span>
</p>

</body>

</html>

 

Many thanks

Enjoy your day

 

Share this post


Link to post

Well, the image source file is specified using a relative path. But what is it relative to? If you open a HTML file in a web browser the path is relative to the folder the HTML file resides in, if you serve the HTML from a web server it is relative to the folder defined as root for the web page. If you load the HTML directly into a TWebbrowser it may be relative to the current directory as seen by the running program.

As a test set the current directory in the program to the folder that contains the img subfolder, using the System.IOUtils.TDirectory.SetCurrentDirectory method, before loading the HTML string. Oh, and forget the old file functions, TFile from System.IOUtils has ReadAllText method that does the job in one line...

Share this post


Link to post

Oh thanks Peter!!

Makes totally sense- it works now !


And cheers for the ReadAllText, didn't knew that one, makes life simple 🙂

 

Another question:

I try to hide the scrollbars. My html document is only a few sentences such that no scrolling is needed, however the bar is still there. Even after

adding the following code AFTER loading my html page

  // hide scrollbar
  wbBrowser.OleObject.Document.Body.Style.OverflowX := 'hidden';
  wbBrowser.OleObject.Document.Body.Style.OverflowY := 'hidden';

Is there another possibility?

 

Edited by scienceguy

Share this post


Link to post
23 hours ago, scienceguy said:

Another question:

I try to hide the scrollbars. My html document is only a few sentences such that no scrolling is needed, however the bar is still there. Even after

adding the following code AFTER loading my html page

Sorry, I cannot help you with that; my knowledge of TWebBrowser is pretty basic.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×