TWebBrowser出现 Method pasteHTML not supported by automation object 解决方法
2017-04-11 09:37
726 查看
先看下面的源码,在TWebBrowser当前编辑位置插入一个图片,是通过源码的方法插入的。
上面代码中,如果编辑的时不选择任何内容,或者选择了一部分文字,可以正常插入图片,但是如果原来选择的是个图片,或者是其它的比如按钮,录入框,在调用ovTextRange.pasteHTML时会出现 Method pasteHTML not supported by automation object 错误。
解决方法1:
先清空选择对象,如下代码
ovSelection := Edit.OleObject.Document.selection; //获得选择对象
ovSelection.Clear; //先清空
ovTextRange := ovSelection.createRange; // create a TextRange from the current selection
tmpStr := Format('<IMG border=0 hspace=0 src="%s">', [urlStr]);
ovTextRange.pasteHTML(tmpStr);
解决方法2:
判断选择的类型,代码如下
ovSelection := Edit.OleObject.Document.selection; //获得选择对象
if SameText(ovSelection.type, 'Text') or SameText(ovSelection.type, 'None') then //只有选择文本、或不选择的地方可以插入
begin
ovTextRange := ovSelection.createRange; // create a TextRange from the current selection
tmpStr := Format('<IMG border=0 hspace=0 src="%s">', [urlStr]);
ovTextRange.pasteHTML(tmpStr); //粘贴图片源码
end;
var urlStr : string; ovSelection: OleVariant; ovTextRange: OleVariant; tmpStr : string; begin urlStr := 'http://www.1and1-mail.com/imgv2/pic_1.jpg'; ovSelection := Edit.OleObject.Document.selection; //获得选择对象 ovTextRange := ovSelection.createRange; // create a TextRange from the current selection tmpStr := Format('<IMG border=0 hspace=0 src="%s">', [urlStr]); ovTextRange.pasteHTML(tmpStr); //粘贴图片源码 end;
上面代码中,如果编辑的时不选择任何内容,或者选择了一部分文字,可以正常插入图片,但是如果原来选择的是个图片,或者是其它的比如按钮,录入框,在调用ovTextRange.pasteHTML时会出现 Method pasteHTML not supported by automation object 错误。
解决方法1:
先清空选择对象,如下代码
ovSelection := Edit.OleObject.Document.selection; //获得选择对象
ovSelection.Clear; //先清空
ovTextRange := ovSelection.createRange; // create a TextRange from the current selection
tmpStr := Format('<IMG border=0 hspace=0 src="%s">', [urlStr]);
ovTextRange.pasteHTML(tmpStr);
解决方法2:
判断选择的类型,代码如下
ovSelection := Edit.OleObject.Document.selection; //获得选择对象
if SameText(ovSelection.type, 'Text') or SameText(ovSelection.type, 'None') then //只有选择文本、或不选择的地方可以插入
begin
ovTextRange := ovSelection.createRange; // create a TextRange from the current selection
tmpStr := Format('<IMG border=0 hspace=0 src="%s">', [urlStr]);
ovTextRange.pasteHTML(tmpStr); //粘贴图片源码
end;
相关文章推荐
- 出现HTTP Status 405 - HTTP method GET is not supported by this URL 原因及解决方法:
- 在pring框架出现 405 request method post not supported 的解决方法
- servlet中使用service()方法出现错误:HTTP method POST is not supported by this URL
- 关于解决HTTP Status 405 - HTTP method POST is not supported by this URL方法之一
- 关于Servlet报错:405 HTTP method GET is not supported by this URL问题解决方法
- 用OLEDB操作Excel时出现Selected collating sequence not supported by the operating system错误,附解决方法
- VS中 "Duplicate items are not supported by the "Resources" parameter" 解决方法
- 出现HTTP Status 405 - HTTP method GET is not supported by this URL
- Gdk-WARNING **: locale not supported by C library解决方法
- WebApi Put方法出现MethodNotAllowed解决方法
- [转]IDEA 出现编译错误 Multi-catches are not supported a this language level 解决方法
- JQuery 的 ajax 出现Origin null is not allowed by Access-Control-Allow-Origin 解决方法
- 关于jquery html()方法获取带有OBJECT标签的元素内容时,出现“类型不匹配。”的解决办法
- HTTP method GET is not supported by this URL 问题解决
- asp.net连接MYSQL出现Character set 'gbk' is not supported的解决方法
- 阿里云ECS在CentOS 6.9中使用Nginx提示:nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)的解决方法
- 黄聪:VS中 "Duplicate items are not supported by the "Resources" parameter" 解决方法
- 解决HTTP Status 405 - HTTP method POST is not supported by this URL 详解方案
- VS2010 出现错误提示“Error Creating Control - Object reference not set to an instance of an objec” 的解决方法
- Sea.js出现Uncaught TypeError: object is not a function的解决方法