我们知道在设计activex dll程序的事件直接使用以下方法定义就可以,例如:public event tracerview(indexvalue as integer, keyvalue as string, traceresults as string)就定义好了一个给exe程序使用的事件。但我们也知道要使用事件必须有外部动作或定时器才能够触发,但是怎样在activex dll内部触发该事件呢?
我搜索了许多网站的技术文章都没有能找到合适的处理方法,但经过自己的摸索找到了一个好的方法来处理这个问题。或许我太孤陋寡闻吧,我没有看到这方面的文章介绍;如果我下面写的内容有与别人的文章有雷同的地方,请不要认为我又抄袭之嫌。因为下面的内容的确是我摸索的结果。
1、首先我们应该定义好一个activex dll工程,设计一个类比如clyprinter类,并把instancing的属性设为5—multiuse;
2、在clyprinter类模块中添加事件,比如:public event tracerview(indexvalue as integer, keyvalue as string, traceresults as string);
3、在clyprinter类模块中添加一个friend 方法,比如:friend sub captureview(indexvalue as integer, keyvalue as string, traceresults as string)在该方法中添加触发事件的代码raiseevent tracerview(indexvalue, keyvalue, traceresults);
4、在activex dll工程内部添加一个窗体,比如:fgrid窗体;并在该窗体的代码模块中定义引用activex dll的clyprinter类的变量和friend属性,比如以下这样定义:private minitrpt as clyprinter;
friend property get document() as clyprinter
'dll工程类在工程内部使用方式
set document = minitrpt
end property
friend property set document(byval vnewdata as clyprinter)
set minitrpt = vnewdata
end property
5、在fgrid窗体代码模块内部就可以使用clyprinter类的friend、public方法和属性,如:minitrpt.captureview 0, mnuyaymenu.item(0).caption, mnuyaymenu.item(0).tag
通过以上5步就可以在activex dll工程内部使用事件、方法和属性。
如果有什么不同的做法请和我联系。email to tsouan@hotmail.com