Autor Beitrag
violinenspieler1000
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38



BeitragVerfasst: Fr 07.08.09 23:35 
Hallo,

ich möchte HTML in der TWebbrowser darstellen und probiere dazu folgenden Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
       Webbrowser1.navigate('about:black');
       
html:='< HTML>< HEAD>< TITLE>Test< /TITLE>< /HEAD>< BODY>' +
'< b>Test!< /b>< p>' +
'< /BODY>< /HTML>';

      WebBrowser1.OleObject.Document.Write(html);



Leider wird dabei nicht etwa nur "Test!" angezeigt, sondern auch die ganzen "Steuerwörter" wie "<HTML>", "<HEAD>" und "<TITLE>".

1. Wie lässt sich dieses Problem lösen?

2. Angenommen ich möchte ein Bild einbinden, dass ebenfalls dynamisch erzeugt wird. Was muss man dann als source bei "<img src=?????></img>" angeben?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 08.08.09 07:19 
user profile iconviolinenspieler1000 hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
       Webbrowser1.navigate('about:black');					
Also ohne die Leerzeichen und den Tippfehler funktioniert es bei mir problemlos. :nixweiss: (Obwohl du ein Paragraph-Tag ohne passendes End-Tag drin hast.)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var
  html: string;
begin
  Webbrowser1.Navigate('about:blank');

  html:='<HTML><HEAD><TITLE>Test</TITLE></HEAD><BODY>' +
    '<b>Test!</b><p>' +
    '</BODY></HTML>';

  Webbrowser1.OleObject.Document.Write(html);
Und wenn du validen (X)HTML-Code benutzt, dann wird es noch besser klappen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var
  XHtmlSrc: string;
begin
  wbTest.Navigate('about:blank');

  XHtmlSrc := '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
    + '<html xmlns="http://www.w3.org/1999/xhtml">'
    + '<head>'
    + '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
    + '<title>Test</title>'
    + '</head>'
    + '<body>'
    + '<b>Test!</b>'
    + '</body>'
    + '</html>';

  wbTest.OleObject.Document.Write(XHtmlSrc);


Und zu dem Bild schau dir einmal Asynchronous Pluggable Protocols an:
msdn.microsoft.com/e...ibrary/aa767743.aspx
violinenspieler1000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38



BeitragVerfasst: Sa 08.08.09 09:38 
Vielen Dank für die Hilfe.
Es schließt sich jetzt aber die Frage an, warum die Prozedur nur "einmal" funktioniert:
Ruft das Methode mit einem Button auf, wird beim ersten Mal Test wie gewollt angezeigt.
Klickt man aber ein zweites mal darauf wird nur noch ein weißes Feld angezeigt.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 08.08.09 10:44 
Nun ja, was erwartest du denn sonst was passiert, wenn du nach dem schließenden </html> Tag weiteren Html-Quelltext schreibst? Du musst dann den aktuellen Quelltext eben ersetzen.
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
procedure TForm224.btnTestClick(Sender: TObject);

  procedure Delay(Milliseconds: Integer);
  var
    Tick: DWord;
    Event: THandle;
  begin
    Event := CreateEvent(nil, False, False, nil);
    try
      Tick := GetTickCount + DWord(Milliseconds);
      while (Milliseconds > 0) and
            (MsgWaitForMultipleObjects(1, Event, False, Milliseconds, QS_ALLINPUT) <> WAIT_TIMEOUT) do
      begin
        Application.ProcessMessages;
        if Application.Terminated then Exit;
        Milliseconds := Tick - GetTickcount;
      end;
    finally
      CloseHandle(Event);
    end;
  end;

var
  i: Integer;
  XHtmlSrc: string;
begin
  wbTest.Navigate('about:blank');

  XHtmlSrc := '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
    + '<html xmlns="http://www.w3.org/1999/xhtml">'
    + '<head>'
    + '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
    + '<title>Test</title>'
    + '</head>'
    + '<body>'
    + '<b>Test!</b>'
    + '</body>'
    + '</html>';

  wbTest.OleObject.Document.Write(XHtmlSrc);
  for i := 1 to 10 do
  begin
    Delay(400);
    wbTest.OleObject.Document.Body.InnerHtml := 'Test!';
    Delay(400);
    wbTest.OleObject.Document.Body.InnerHtml := '<b>Test!</b>';
  end;
end;