如何把一个string转化为一个ihtmldocument2,不要用webbrowser控件的(因为我的程序里没有,也不要有),string是一串html的代码(从数据库里取出来的)。我用下面的函数:function htmlstrtohtml(str:string):ihtmldocument2;
var hgbl: HGLOBAL;
Stream: IStream;
doc:ihtmldocument2;
psi: IPersistStreamInit;
begin
try hgbl:=GlobalAlloc(GPTR,Length(str)+1);
if 0=hgbl then RaiseLastWin32Error;
CopyMemory(Pointer(hgbl),PChar(str),Length(str));
CreateStreamOnHGlobal(hgbl,True,Stream);
(doc as IPersistStreamInit).Load(stream);
result:=doc;
except
end;
end;
可是在 (doc as IPersistStreamInit).Load(stream)这句出错
究其原因,应该是doc这个ihtmldocument2对象没有实体,假如我放个Twebbrowser然后加入一句: doc:=webbrowser1.document as ihtmldocument2;
这样可以正常运行现请问如何创建这个doc(ihtmldocument2 )?
(一定不要有Twebbrowser控件)
var hgbl: HGLOBAL;
Stream: IStream;
doc:ihtmldocument2;
psi: IPersistStreamInit;
begin
try hgbl:=GlobalAlloc(GPTR,Length(str)+1);
if 0=hgbl then RaiseLastWin32Error;
CopyMemory(Pointer(hgbl),PChar(str),Length(str));
CreateStreamOnHGlobal(hgbl,True,Stream);
(doc as IPersistStreamInit).Load(stream);
result:=doc;
except
end;
end;
可是在 (doc as IPersistStreamInit).Load(stream)这句出错
究其原因,应该是doc这个ihtmldocument2对象没有实体,假如我放个Twebbrowser然后加入一句: doc:=webbrowser1.document as ihtmldocument2;
这样可以正常运行现请问如何创建这个doc(ihtmldocument2 )?
(一定不要有Twebbrowser控件)
解决方案 »
- 推荐几个免费的DELPHI的界面库
- ***很久以前,delphi的程序员会攻击vb,现在borland不玩了,你们还能跳起来吗?*****
- DBLookupComboBox绑定问题,急救
- 如何用程序把输入法切换成英文输入状态?请大虾们帮忙!
- Treeview和数据库的问题
- 急:高速扫描仪开发问题.
- 如何在treeview中插入背景图,或使它成为透明也可以。
- bewill(海咪咪),近来界分
- 还是几个极菜的问题!!!!请拉兄弟一把!!!!
- 如何改变DBGrid网格颜色,用到什么事件?除了OnDrawColumnCell和onGetCellParam还有别的事件吗
- 请教使用wininet的几个问题(up有分)
- 为什么会interface not supported
只是后者要显示,成本并没有省下什么。
FHtmlDoc: IHTMLDocument2;CoCreateInstance(CLASS_HTMLDocument, nil, CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, FHtmlDoc);
它们主要差别也就在IDocHostUIHandler and IDocHostShowUI接口实现上。
脚本引擎,Microsoft virtual machine,ActiveX Controls,插件,
HTML文档里面用到的其它对象,在创建MSHTML组件的时候都会创建。
它们耗资源相当重的。
对于很简单情况下的HTML解析,比如找出网页里面链接什么,我是宁愿自己
写代码处理HTML文本。