为什么总报告说:不会实现接口成员?

triout 2004-07-28 03:00:10
写了个类,继承自IHTMLDocument接口,但编译报告说不会实现接口:

C:\Documents and Settings\daview\桌面\浏览器\Form1.cs(310): “Explorer.MyDocument”不会实现接口成员“mshtml.IHTMLDocument.Script”
C:\Documents and Settings\daview\桌面\浏览器\Form1.cs(310): “Explorer.MyDocument”不会实现接口成员“mshtml.IHTMLDocument2.activeElement”
C:\Documents and Settings\daview\桌面\浏览器\Form1.cs(310): “Explorer.MyDocument”不会实现接口成员“mshtml.IHTMLDocument2.alinkColor”
C:\Documents and Settings\daview\桌面\浏览器\Form1.cs(310): “Explorer.MyDocument”不会实现接口成员“mshtml.IHTMLDocument2.all”
C:\Documents and Settings\daview\桌面\浏览器\Form1.cs(310): “Explorer.MyDocument”不会实现接口成员“mshtml.IHTMLDocument2.anchors”
C:\Documents and Settings\daview\桌面\浏览器\Form1.cs(310): “Explorer.MyDocument”不会实现接口成员“mshtml.IHTMLDocument2.applets”
C:\Documents and Settings\daview\桌面\浏览器\Form1.cs(310): “Explorer.MyDocument”不会实现接口成员“mshtml.IHTMLDocument2.bgColor”


代码如下:

public class MyDocument:mshtml.IHTMLDocument2//.IHTMLDocument2
{
private IHTMLDocument2 m_Document;
public MyDocument()
{
}
public IHTMLDocument2 Document
{
set
{
this.m_Document=value;
}
}

public mshtml.IHTMLElementCollection scripts()
{
return this.m_Document.scripts();
}
public object Script()
{
return this.m_Document.Script();
}
public mshtml.IHTMLElement activeElement()
{
return this.m_Document.activeElement();
}
public object alinkColor()
{
return this.m_Document.alinkColor();
}
public mshtml.IHTMLElementCollection all()
{
return this.m_Document.all();
}
public mshtml.IHTMLElementCollection anchors()
{
return this.m_Document.anchors();
}
public mshtml.IHTMLElementCollection applets()
{
return this.m_Document.applets();
}
public object bgColor()
{
return this.m_Document.bgColor();
}
}
...全文
798 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
triout 2004-07-28
  • 打赏
  • 举报
回复
对,我以前都是手工添加接口函数定义的,没有注意这个功能。

开始编辑的发现了这个功能,所以使用了,结果就是正确了。


非常感谢wenson()的跟贴!

(可惜不能给自己分:(
wenson 2004-07-28
  • 打赏
  • 举报
回复
我这边的问题解决,总体上讲,实现一个接口是很简单的,VS会帮助你自动实现接口的stub,就是在你输入继承接口时,VS会提示“press tab key产生接口的stub”,另外在当前的项目中要添加类库的引用和相关的using,我想应该问题不大了
triout 2004-07-28
  • 打赏
  • 举报
回复
对,很多都是属性,而不是方法,这就是错误。

谢谢!
triout 2004-07-28
  • 打赏
  • 举报
回复
问题解决,感谢各位的跟贴。
wenson 2004-07-28
  • 打赏
  • 举报
回复
IHTMLDocument2 的成员可以通过在vs中点击“转到定义”来查看
wenson 2004-07-28
  • 打赏
  • 举报
回复
把mshtml.IHTMLDocument去掉试试,我也刚碰到这个情况,正在调试,等回再来回复
triout 2004-07-28
  • 打赏
  • 举报
回复
public class MyDocument:mshtml.IHTMLDocument2//.IHTMLDocument2
{
private IHTMLDocument2 m_Document;
public MyDocument()
{
}

public mshtml.IHTMLElementCollection scripts()
{
return this.m_Document.scripts();
}
public object Script()
{
return this.m_Document.Script();
}
public mshtml.IHTMLElement activeElement()
{
return this.m_Document.activeElement();
}
public object alinkColor()
{
return this.m_Document.alinkColor();
}
public mshtml.IHTMLElementCollection all()
{
return this.m_Document.all();
}
public mshtml.IHTMLElementCollection anchors()
{
return this.m_Document.anchors();
}
public mshtml.IHTMLElementCollection applets()
{
return this.m_Document.applets();
}
public object bgColor()
{
return this.m_Document.bgColor();
}
public mshtml.IHTMLElementCollection body()
{
return this.m_Document.body();
}
public string charset()
{
return this.m_Document.charset();
}
public void clear()
{
this.m_Document.clear();
}
public void close()
{
this.m_Document.close();
}
public string cookie()
{
return this.m_Document.cookie();
}
public mshtml.IHTMLElement createElement(string eTag)
{
return this.m_Document.createElement(eTag);
}
public mshtml.IHTMLStyleSheet createStyleSheet(string bstrHref, int lIndex)
{
return this.m_Document.createStyleSheet(bstrHref, lIndex);
}
public string defaultCharset()
{
return this.m_Document.defaultCharset();
}
public string designMode()
{
return this.m_Document.designMode();
}
public string domain()
{
return this.m_Document.domain();
}
public mshtml.IHTMLElement elementFromPoint(int x, int y)
{
return this.m_Document.elementFromPoint(x,y);
}
public mshtml.IHTMLElementCollection embeds()
{
return this.m_Document.embeds();
}
public bool execCommand(string cmdID, bool showUI, object Value)
{
return this.m_Document.execCommand(cmdID, showUI, Value);
}
public bool execCommandShowHelp(string cmdID)
{
return this.m_Document.execCommandShowHelp(cmdID);
}
public bool expando()
{
return this.m_Document.expando();
}
public object fgColor()
{
return this.m_Document.fgColor();
}
public string fileCreatedDate()
{
return this.m_Document.fileCreatedDate();
}
public string fileModifiedDate()
{
return this.m_Document.fileModifiedDate();
}
public string fileSize()
{
return this.m_Document.fileSize();
}
public string fileUpdatedDate()
{
return this.m_Document.fileUpdatedDate();
}
public mshtml.IHTMLElementCollection forms()
{
return this.m_Document.forms();
}
public mshtml.FramesCollection frames()
{
return this.m_Document.frames();
}
public mshtml.IHTMLElementCollection images()
{
return this.m_Document.images();
}
public string lastModified()
{
return this.m_Document.lastModified();
}
public object linkColor()
{
return this.m_Document.linkColor();
}
public mshtml.IHTMLElementCollection links()
{
return this.m_Document.links();
}
public mshtml.HTMLLocation location()
{
return this.m_Document.location();
}
public string mimeType()
{
return this.m_Document.mimeType();
}
public string nameProp()
{
return this.m_Document.nameProp();
}
public object onafterupdate()
{
return this.m_Document.onafterupdate();
}
public object onbeforeupdate()
{
return this.m_Document.onbeforeupdate();
}
public object onclick()
{
return this.m_Document.onclick();
}
public object ondblclick()
{
return this.m_Document.ondblclick();
}
public object ondragstart()
{
return this.m_Document.ondragstart();
}
public object onerrorupdate()
{
return this.m_Document.onerrorupdate();
}
public object onhelp()
{
return this.m_Document.onhelp();
}
public object onkeydown()
{
return this.m_Document.onkeydown();
}
public object onkeypress()
{
return this.m_Document.onkeypress();
}
public object onkeyup()
{
return this.m_Document.onkeyup();
}
public object onmousedown()
{
return this.m_Document.onmousedown();
}
public object onmousemove()
{
return this.m_Document.onmousemove();
}
public object onmouseout()
{
return this.m_Document.onmouseout();
}
public object onmouseover()
{
return this.m_Document.onmouseover();
}
public object onmouseup()
{
return this.m_Document.onmouseup();
}
public object onreadystatechange()
{
return this.m_Document.onreadystatechange();
}
public object onrowenter()
{
return this.m_Document.onrowenter();
}
public object onrowexit()
{
return this.m_Document.onrowexit();
}
public object onselectstart()
{
return this.m_Document.onselectstart();
}
public object open(string url, object name, object features, object replace)
{
return this.m_Document.open(url, name, features, replace);
}
public mshtml.IHTMLWindow2 parentWindow()
{
return this.m_Document.parentWindow();
}
public mshtml.IHTMLElementCollection plugins()
{
return this.m_Document.plugins();
}
public string protocol()
{
return this.m_Document.protocol();
}
public bool queryCommandEnabled(string cmdID)
{
return this.m_Document.queryCommandEnabled(cmdID);
}
public bool queryCommandIndeterm(string cmdID)
{
return this.m_Document.queryCommandIndeterm(cmdID);
}
public bool queryCommandState(string cmdID)
{
return this.m_Document.queryCommandState(cmdID);
}
public bool queryCommandSupported(string cmdID)
{
return this.m_Document.queryCommandSupported(cmdID);
}
public string queryCommandText(string cmdID)
{
return this.m_Document.queryCommandText(cmdID);
}
public object queryCommandValue(string cmdID)
{
return this.m_Document.queryCommandValue(cmdID);
}
public string readyState()
{
return this.m_Document.readyState();
}
public string referrer()
{
return this.m_Document.referrer();
}
public string security()
{
return this.m_Document.security();
}
public mshtml.IHTMLSelectionObject selection()
{
return this.m_Document.selection();
}
public mshtml.IHTMLStyleSheetsCollection styleSheets()
{
return this.m_Document.styleSheets();
}
public string title()
{
return this.m_Document.title();
}
public string toString()
{
return this.m_Document.toString();
}
public string url()
{
return this.m_Document.url();
}
public object vlinkColor()
{
return this.m_Document.vlinkColor();
}
public void write(params object[] psarry)
{
this.m_Document.write(psarry);
}
public void writeln(params object[] psarry)
{
this.m_Document.writeln(psarry);
}
public IHTMLDocument2 Document
{
// get
// {
// return this.m_Document;
// }
set
{
this.m_Document=value;
}
}
}
triout 2004-07-28
  • 打赏
  • 举报
回复
我是这样的:

创建了一个WebBrowser控件对象,由于有些东西没有办法控制,想看进入到Document对象里面看能否控制(至少检测到访问流等),所以我重写了AxWebBrowser和IHTMLDocument2。

代码如下:

public class MyBrowser:AxSHDocVw.AxWebBrowser
{
public MyBrowser()
{
}
public override void Navigate(string uRL, ref object flags, ref object targetFrameName, ref object postData, ref object headers)
{
Debug.WriteLine("MyBrowser.Navigate:"+uRL);
base.Navigate (uRL, ref flags, ref targetFrameName, ref postData, ref headers);
}

public override void Navigate2(ref object uRL, ref object flags, ref object targetFrameName, ref object postData, ref object headers)
{
Debug.WriteLine("MyBrowser.Navigate2:"+uRL);
base.Navigate2 (ref uRL, ref flags, ref targetFrameName, ref postData, ref headers);
}

private object m_document;

public override object Document
{
get
{
if(this.m_document==null)
{
MyDocument myDoc=new MyDocument();
myDoc.Document=base.Document as IHTMLDocument2;
this.m_document=myDoc;
}
return this.m_document;
//return base.Document;
}
}

}
mywebcom 2004-07-28
  • 打赏
  • 举报
回复
你真地实现了接口的成员吗???
“return this.m_Document.scripts();”
类似的这些语句里面,“m_Document”你都没有实现,你就可以用它么???
“m_Document”,你定义的是一个接口,但是呢,你又继承了该接口,继承该接口,是为了实现里面的功能。
triout 2004-07-28
  • 打赏
  • 举报
回复
现在,我感到很奇怪:

自己写的测试接口和继承的类,如果只实现了接口的部分方法,那么报告错误是不会把已经实现的方法放在列表中的。

而上面的代码中,明明那些类已经实现了,却还是报告这些错误。
mywebcom 2004-07-28
  • 打赏
  • 举报
回复
提示问题很清楚:你没有实现接口成员。

所以对于接口里面的每个成员你都要在你的类里面实现它;
如果参数不对,会提示另外的错误;
接口只是一个简单的描述子类可以完成的工作,所以它并不完成任何具体的任务,并且它不能实例化。
zzcwhq 2004-07-28
  • 打赏
  • 举报
回复
你写的类是否覆盖了接口成员,
是否全部实现了接口成员,
看看接口有没有继承接口等
triout 2004-07-28
  • 打赏
  • 举报
回复
下面是我实现的所有方法:

// public mshtml.IHTMLElementCollection scripts()
// {
// return this.m_Document.scripts();
// }
// public object Script()
// {
// return this.m_Document.Script();
// }
// public mshtml.IHTMLElement activeElement()
// {
// return this.m_Document.activeElement();
// }
// public object alinkColor()
// {
// return this.m_Document.alinkColor();
// }
// public mshtml.IHTMLElementCollection all()
// {
// return this.m_Document.all();
// }
// public mshtml.IHTMLElementCollection anchors()
// {
// return this.m_Document.anchors();
// }
// public mshtml.IHTMLElementCollection applets()
// {
// return this.m_Document.applets();
// }
// public object bgColor()
// {
// return this.m_Document.bgColor();
// }
// public mshtml.IHTMLElementCollection body()
// {
// return this.m_Document.body();
// }
// public string charset()
// {
// return this.m_Document.charset();
// }
// public void clear()
// {
// this.m_Document.clear();
// }
// public void close()
// {
// this.m_Document.close();
// }
// public string cookie()
// {
// return this.m_Document.cookie();
// }
// public mshtml.IHTMLElement createElement(string eTag)
// {
// return this.m_Document.createElement(eTag);
// }
// public mshtml.IHTMLStyleSheet createStyleSheet(string bstrHref, int lIndex)
// {
// return this.m_Document.createStyleSheet(bstrHref, lIndex);
// }
// public string defaultCharset()
// {
// return this.m_Document.defaultCharset();
// }
// public string designMode()
// {
// return this.m_Document.designMode();
// }
// public string domain()
// {
// return this.m_Document.domain();
// }
// public mshtml.IHTMLElement elementFromPoint(int x, int y)
// {
// return this.m_Document.elementFromPoint(x,y);
// }
// public mshtml.IHTMLElementCollection embeds()
// {
// return this.m_Document.embeds();
// }
// public bool execCommand(string cmdID, bool showUI, object Value)
// {
// return this.m_Document.execCommand(cmdID, showUI, Value);
// }
// public bool execCommandShowHelp(string cmdID)
// {
// return this.m_Document.execCommandShowHelp(cmdID);
// }
// public bool expando()
// {
// return this.m_Document.expando();
// }
// public object fgColor()
// {
// return this.m_Document.fgColor();
// }
// public string fileCreatedDate()
// {
// return this.m_Document.fileCreatedDate();
// }
// public string fileModifiedDate()
// {
// return this.m_Document.fileModifiedDate();
// }
// public string fileSize()
// {
// return this.m_Document.fileSize();
// }
// public string fileUpdatedDate()
// {
// return this.m_Document.fileUpdatedDate();
// }
// public mshtml.IHTMLElementCollection forms()
// {
// return this.m_Document.forms();
// }
// public mshtml.FramesCollection frames()
// {
// return this.m_Document.frames();
// }
// public mshtml.IHTMLElementCollection images()
// {
// return this.m_Document.images();
// }
// public string lastModified()
// {
// return this.m_Document.lastModified();
// }
// public object linkColor()
// {
// return this.m_Document.linkColor();
// }
// public mshtml.IHTMLElementCollection links()
// {
// return this.m_Document.links();
// }
// public mshtml.HTMLLocation location()
// {
// return this.m_Document.location();
// }
// public string mimeType()
// {
// return this.m_Document.mimeType();
// }
// public string nameProp()
// {
// return this.m_Document.nameProp();
// }
// public object onafterupdate()
// {
// return this.m_Document.onafterupdate();
// }
// public object onbeforeupdate()
// {
// return this.m_Document.onbeforeupdate();
// }
// public object onclick()
// {
// return this.m_Document.onclick();
// }
// public object ondblclick()
// {
// return this.m_Document.ondblclick();
// }
// public object ondragstart()
// {
// return this.m_Document.ondragstart();
// }
// public object onerrorupdate()
// {
// return this.m_Document.onerrorupdate();
// }
// public object onhelp()
// {
// return this.m_Document.onhelp();
// }
// public object onkeydown()
// {
// return this.m_Document.onkeydown();
// }
// public object onkeypress()
// {
// return this.m_Document.onkeypress();
// }
// public object onkeyup()
// {
// return this.m_Document.onkeyup();
// }
// public object onmousedown()
// {
// return this.m_Document.onmousedown();
// }
// public object onmousemove()
// {
// return this.m_Document.onmousemove();
// }
// public object onmouseout()
// {
// return this.m_Document.onmouseout();
// }
// public object onmouseover()
// {
// return this.m_Document.onmouseover();
// }
// public object onmouseup()
// {
// return this.m_Document.onmouseup();
// }
// public object onreadystatechange()
// {
// return this.m_Document.onreadystatechange();
// }
// public object onrowenter()
// {
// return this.m_Document.onrowenter();
// }
// public object onrowexit()
// {
// return this.m_Document.onrowexit();
// }
// public object onselectstart()
// {
// return this.m_Document.onselectstart();
// }
// public object open(string url, object name, object features, object replace)
// {
// return this.m_Document.open(url, name, features, replace);
// }
// public mshtml.IHTMLWindow2 parentWindow()
// {
// return this.m_Document.parentWindow();
// }
// public mshtml.IHTMLElementCollection plugins()
// {
// return this.m_Document.plugins();
// }
// public string protocol()
// {
// return this.m_Document.protocol();
// }
// public bool queryCommandEnabled(string cmdID)
// {
// return this.m_Document.queryCommandEnabled(cmdID);
// }
// public bool queryCommandIndeterm(string cmdID)
// {
// return this.m_Document.queryCommandIndeterm(cmdID);
// }
// public bool queryCommandState(string cmdID)
// {
// return this.m_Document.queryCommandState(cmdID);
// }
// public bool queryCommandSupported(string cmdID)
// {
// return this.m_Document.queryCommandSupported(cmdID);
// }
// public string queryCommandText(string cmdID)
// {
// return this.m_Document.queryCommandText(cmdID);
// }
// public object queryCommandValue(string cmdID)
// {
// return this.m_Document.queryCommandValue(cmdID);
// }
// public string readyState()
// {
// return this.m_Document.readyState();
// }
// public string referrer()
// {
// return this.m_Document.referrer();
// }
// public string security()
// {
// return this.m_Document.security();
// }
// public mshtml.IHTMLSelectionObject selection()
// {
// return this.m_Document.selection();
// }
// public mshtml.IHTMLStyleSheetsCollection styleSheets()
// {
// return this.m_Document.styleSheets();
// }
// public string title()
// {
// return this.m_Document.title();
// }
// public string toString()
// {
// return this.m_Document.toString();
// }
// public string url()
// {
// return this.m_Document.url();
// }
// public object vlinkColor()
// {
// return this.m_Document.vlinkColor();
// }
// public void write(params object[] psarry)
// {
// this.m_Document.write(psarry);
// }
// public void writeln(params object[] psarry)
// {
// this.m_Document.writeln(psarry);
// }
triout 2004-07-28
  • 打赏
  • 举报
回复
To langmafeng(乞力马扎罗):

参数都对的。

To mywebcom(我):

上面的代码有删节。

IHTMLDocument2有几个成员我不清楚,但当我写一个继承自IHTMLDocument2的类的时候,一编译就会报告有那些函数没有实现,所以我复制了错误信息,然后粘贴到代码中进行修改的。

而且,后来报告的错误里列举的不会实现的方法还是只包括那些我已经实现了的方法。
TrustNone 2004-07-28
  • 打赏
  • 举报
回复
参数不对
mywebcom 2004-07-28
  • 打赏
  • 举报
回复
你首先要知道你的接口里面有没有那些成员:IHTMLDocument2 下面有几个成员???
langmafeng 2004-07-28
  • 打赏
  • 举报
回复
参数对不对?
triout 2004-07-28
  • 打赏
  • 举报
回复
反而会对某些方法报告说需要静态、公共什么的错误提示。
triout 2004-07-28
  • 打赏
  • 举报
回复
没有用
mywebcom 2004-07-28
  • 打赏
  • 举报
回复
除掉前面的 “public private” 等修饰符。

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧