如何使用 Javascript 在运行时以编程方式检查 ActiveXObject?
我正在寻找为 ActiveX 对象创建一个 Javascript 库,以实现可链接性。
例如,我希望
var dbEngine=new ActiveXObject('DAO.DBEngine.36');
var dbs=dbEngine.OpenDatabase('D:\\Todo.mdb');
var rs=dbs.OpenRecordset('SELECT * FROM ListItems');
用类似这样的东西(a la jQuery)替换它:
var rs=AX('DAO.DBEngine.36')
.OpenDatabase('D:\\Todo.mdb')
.OpenRecordset('SELECT * FROM ListItems');
我知道我可以这样做:
var rs=new ActiveXObject('DAO.DBEngine.36')
.OpenDatabase('D:\\Todo.mdb')
.OpenRecordset('SELECT * FROM ListItems');
但我无法从 Recordset 对象访问数据库对象。
为此,AX 函数应在内部创建 DBEngine 对象并检查其成员/属性,然后在返回的对象上公开相应的方法。
如果成员/属性返回一个对象,则该对象本身将包装在 AX 函数中返回。
I am looking to create a Javascript library for ActiveX objects, enabling chainability.
For example, I am looking to replace this:
var dbEngine=new ActiveXObject('DAO.DBEngine.36');
var dbs=dbEngine.OpenDatabase('D:\\Todo.mdb');
var rs=dbs.OpenRecordset('SELECT * FROM ListItems');
with something like this (a la jQuery):
var rs=AX('DAO.DBEngine.36')
.OpenDatabase('D:\\Todo.mdb')
.OpenRecordset('SELECT * FROM ListItems');
I know I can do this:
var rs=new ActiveXObject('DAO.DBEngine.36')
.OpenDatabase('D:\\Todo.mdb')
.OpenRecordset('SELECT * FROM ListItems');
but I have no way of accessing the Database object from the Recordset object.
In order to do this, the AX function should create the DBEngine object internally and inspect its members/properties, then expose corresponding methods on the the returned object.
If the member/property returns an object, that object itself will be returned wrapped in the AX function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只有实现 IDispatchEx 的对象才能在运行时检查。 MSDN专门列出了IDispatch和IDispatchEx之间的区别:
我已将相关问题加粗。
正如埃里克在评论中指出的那样,您可以使用 foreach (或 for...in 也许?)来枚举对象的成员,但从问题中我不确定您具体想要做什么。
由于并非所有 ActiveX 控件都会实现 IDispatchEx(或者可能无法正确或完全实现 IDispatchEx 的所有方法),因此您是否希望使用特定的控件?
更多细节将带来更好的答案。
Only objects that implement IDispatchEx can be inspected at runtime. MSDN specifically lists the differences between IDispatch and IDispatchEx:
I've made bold the relevant issue.
As Eric points out in the comments, you can use enumerate the members of the objects using foreach (or for...in perhaps?), but I'm not sure, from the question, what you specifically want to do.
Since not all ActiveX controls will implement IDispatchEx (or may not implement all methods of IDispatchEx properly or completely), are there specific controls you're looking to play with?
More details will lead to better answers.