解决Delphi中webbrowser 不能复制粘贴问题
uses Activex;
procedure TForm1.FormDestroy(Sender: TObject);
begin
oleuninitialize;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
oleinitialize(nil);
end ;
解决TWebbrowser打开paypal出错
procedure TForm1.FormCreate(Sender: TObject);
begin
Set8087CW(Longword($133f)); //关闭TWebbrowser打开paypal出错这个机制
end;
Delphi默认是截获后又把异常抛了出来,被系统截获就会影响程序运行了
borland给的解决方法是,加一句Set8087CW(Longword($133f));来关闭这个机制. 你可以加在form的oncreate事件里
如何在WebBrowser1控件直接显示HTML代码
uses ActiveX,mshtml;
//方法一
procedure writeHTML(WebInfo:TWebBrowser;text:String);
var
HTMLDoc: IHTMLDocument2;
v:Variant;
begin
WebInfo.Navigate('about:blank', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
while WebInfo.ReadyState <> READYSTATE_COMPLETE do
begin
Application.ProcessMessages;
Sleep(0);
end;
if Assigned(WebInfo.Document) then
begin
HTMLDoc := WebInfo.Document as IHTMLDocument2;
v := VarArrayCreate([0, 0], varVariant);
v[0] := text; // Here's your HTML string
HTMLDoc.clear;
HTMLDoc.Write(PSafeArray(TVarData(v).VArray));
HTMLDoc.Close;
v:=Unassigned;
end;
end;
//上面为WebBrowser载入HTML代码
//方法二
procedure LoadStream(WebBrowser: TWebBrowser; Stream: TStream);
var
PersistStreamInit: IPersistStreamInit;
StreamAdapter: IStream;
MemoryStream: TMemoryStream;
begin
WebBrowser.Navigate('about:blank');
repeat
Application.ProcessMessages;
Sleep(0);
until (WebBrowser.ReadyState = READYSTATE_COMPLETE) and (Not WebBrowser.Busy);
if WebBrowser.Document.QueryInterface(IPersistStreamInit,
PersistStreamInit) = S_OK then
begin
if PersistStreamInit.InitNew = S_OK then
begin
MemoryStream:= TMemoryStream.Create;
try
MemoryStream.CopyFrom(Stream, 0);
MemoryStream.Position:= 0;
except
MemoryStream.Free;
raise;
end;
StreamAdapter:= TStreamAdapter.Create(MemoryStream, soOwned);
PersistStreamInit.Load(StreamAdapter);
//以下代码用于屏蔽经常出现的网页脚本执行错误
(WebBrowser.Document as IHTMLDocument2).body.insertAdjacentHTML('afterbegin',
'var noOp = null;');
end;
end;
end;
//上面以流方式加载数据到WebBrowser控件