这种情况我也遇到过了,我是这样解决的:在WebBrowser直接载入流,不通过文件。
///////Begin Source
uses ActiveX;
function ShowHtml(mWebBrowser: TWebBrowser; mStrings: TStrings): Boolean;
var
vMemoryStream: TMemoryStream;
begin
Result := False;
if not (Assigned(mStrings) and Assigned(mWebBrowser)) then Exit;
mWebBrowser.Navigate('about:blank');
if not Assigned(mWebBrowser.Document) then Exit;
vMemoryStream := TMemoryStream.Create;
try
mStrings.SaveToStream(vMemoryStream);
try
vMemoryStream.Position := 0;
Application.ProcessMessages; //
(mWebBrowser.Document as IPersistStreamInit).Load(
TStreamAdapter.Create(vMemoryStream));
except
Exit;
end;
finally
vMemoryStream.Free;
end;
Result := True;
end; { ShowHtml }
///////End Source
///////Begin Demo
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowHtml(WebBrowser1, Memo1.Lines);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Memo1.Text :=
'<html>'#13#10 +
'<body bkcolor=#FF00FF><b>Hello Worlds!</b></body>'#13#10 +
'</html>'#13#10;
end;
///////End Demo