输出COM对象类型信息(从临时文件读取)
By
admin
at 2017-12-07 • 0人收藏 • 1669人看过
//输出COM对象类型信息
import com;
import console
var fs = com.CreateObject("Scripting.FileSystemObject")
//输出com对象成员
dumpObject = function(obj) {
var t = {};
var file = io.tmpname();
io.stdout.reopen(file, "w+t");
com.DumpTypeInfo(fs)
io.stdout.reopen("CONOUT$", "w+t")
for line in io.lines(file) {
var pattern = "(.+)\:\s(.+)";
for k, v in string.gmatch(string.trim(line), pattern) {
t[k] = string.trim(v)
}
}
return t;
}
obj = dumpObject(fs);
console.dump(obj)
console.pause()感谢群里: CodeX 分享.
这样得到数据表之后,就可以想给谁显示就给谁.
1 个回复 | 最后更新于 2018-04-04
登录后方可回帖
写了一个完整的com组件函数并输出到edit示例:
import win.ui; /*DSG{{*/ var winform = win.form(text="COM组件函数查看演示";right=759;bottom=455;border="dialog frame") winform.add( button={cls="button";text="查看该组件内置函数";left=566;top=419;right=756;bottom=450;z=3}; comEdit={cls="edit";text="ADODB.Connection";left=318;top=419;right=545;bottom=448;align="center";bgcolor=0;color=65280;edge=1;font=LOGFONT(h=-16);z=2}; funcEdit={cls="edit";left=5;top=4;right=756;bottom=416;bgcolor=0;color=65280;font=LOGFONT(name='微软雅黑';h=-14);hscroll=1;multiline=1;readonly=1;vscroll=1;z=1} ) /*}}*/ var loadFunc = function( comMsg ){ import com; //调用COM组件 obj = com.CreateObject( comMsg ); //获取COM组件类型库信息 var typeinfo = com.GetTypeInfo(obj) //准备存储获取到的类型库信息 var funcTab = {}; //下面直接调用函数总数目不准确,因为有写com组件里有空函数 //winform.funcEdit.log("共有函数: "++typeinfo.GetTypeAttr().Funcs ++ " 个!",'\r\n'); for(i=8;typeinfo.GetTypeAttr().Funcs-1;1){ table.push(funcTab,table.clone(typeinfo.GetFuncDesc(i) )); } for(i=1;#funcTab;1){ var funcPara = null;//参数合成 if(funcTab[i].Params != null){ //console.dump(funcTab[i]); //总共几个变量参数 for(j=1;funcTab[i].Params;1){ var parametersTab = (funcTab[i].parameters)[j]; if( parametersTab != null ){ //console.dump(parametersTab); if(j==1){ funcPara = string.concat(funcPara,parametersTab._com_type," ",parametersTab.name); }else { funcPara = string.concat(funcPara,',',parametersTab._com_type," ",parametersTab.name); } } } //输出 winform.funcEdit.log(string.concat(funcTab[i]._com_type ," ",funcTab[i].name ,"( ",funcPara , " );"),'\r\n'); } } } winform.button.oncommand = function(id,event){ winform.funcEdit.clear(); loadFunc(winform.comEdit.text); } winform.show() win.loopMessage();再此, 感谢群里: 王港 kio1 codex 阿法牛 indertust ...等人对我的指导!