为什么我的这段代码没有在WebBrowser中显示呢?(300分)

  • 主题发起人 主题发起人 飘摇客
  • 开始时间 开始时间

飘摇客

Unregistered / Unconfirmed
GUEST, unregistred user!
这个是CSDN版主写的,我用了可是没有显示网页,右键单击显示Html源文件,但是就是不显示网页。
function TDM.ShowHtmls(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;
 
你的代碼我也用過一樣沒反應.
我改過別人的,很好用:

procedure TMYWebBrowser.Clear;
var
URL: OleVariant;
begin
URL := 'about:blank';
Navigate2(URL);
end;

procedure TMYWebBrowser.SetHtml(const Html: string);
var
Stream: IStream;
hHTMLText: HGLOBAL;
psi: IPersistStreamInit;
begin
if Busy then Stop;
if not Assigned(Document) then Clear;
while (ReadyState <> ReadyState_Complete) do
forms.Application.ProcessMessages;
hHTMLText := GlobalAlloc(GPTR, Length(Html) + 1);
if 0 = hHTMLText then RaiseLastWin32Error; //old delphi
//if 0 = hHTMLText then RaiseLastOSError;
CopyMemory(Pointer(hHTMLText),
PChar(Html), Length(Html));
OleCheck(CreateStreamOnHGlobal
(hHTMLText, True, Stream));
try
OleCheck(Document.QueryInterface(IPersistStreamInit, psi));
try
OleCheck(psi.InitNew);
OleCheck(psi.Load(Stream));
finally
psi := nil;
end;
finally
Stream := nil;
end;
end;


var
st:TStringList;

MYWebBrowser1.SetHtml(St1.Text);
 
我搞定了,原代码是可用的,我的Html源文件错误了,问题已经解决。
 
接受答案了.
 

Similar threads

后退
顶部