Einzelnen Beitrag anzeigen

shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#4

Re: LoadHTMLToWebBrowser(Webbrowser1,'01.htm');

  Alt 13. Sep 2007, 13:47
So geht's:

Delphi-Quellcode:
procedure WaitForBrowser(WebBrowser:TWebBrowser);
begin
   while WebBrowser.ReadyState <> READYSTATE_COMPLETE do
   begin
      Application.ProcessMessages;
      Sleep(50);
   end;
end;

procedure Document_SetHTML(Document: IDispatch; const HTMLCode: string);
var
  ms: TStringStream;
begin
   if Assigned(Document) then
   begin
      ms := TStringStream.Create(HTMLCode);
      try
         ms.Seek(0, 0);
         OleCheck((Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms)));
      finally
         ms.Free;
      end;
   end;
end;

function Document_GetHTML(Document: IDispatch):string;
var
   ms: TStringStream;
begin
   Result := '';
   if Assigned(Document) then
   begin
      ms := TStringStream.Create(Result);
      try
         OleCheck((Document as IPersistStreamInit).Save(TStreamAdapter.Create(ms),False));
         Result := ms.DataString;
      finally
         ms.Free;
      end;
   end;
end;

procedure WB_SetHTML(WebBrowser: TWebBrowser; const HTMLCode: string);
begin
   if not Assigned(WebBrowser.Document) then
      WebBrowser.Navigate('about:blank');
   WaitForBrowser(WebBrowser);

   Document_SetHTML(WebBrowser.Document, HTMLCode);
end;

function WB_GetHTML(WebBrowser: TWebBrowser): string;
begin
   Result := Document_GetHTML(WebBrowser.Document);
end;
Aufruf:
WB_SetHTML(WebBrowser1, AHTMLCode.Text);
Andreas
  Mit Zitat antworten Zitat