请先参考
http://www.csdn.net/expert/topic/885/885033.xml?temp=.8302881
解决方案还得有空做个试验才行。
http://www.csdn.net/expert/topic/885/885033.xml?temp=.8302881
解决方案还得有空做个试验才行。
解决方案 »
- 怎么把combo里重复的项去掉了
- 怎样改变按钮的背景颜色?
- 如何在MSFGrid中的某个TextMatrix(i,j)中显示图片,并且是居中显示!!
- 应急
- 关于"关闭"的问题!
- VB6中的TabStrip控件在界面设计时很不方便,各位谁有能代替它的控件呢?送分!
- 感谢Hiwax()为我解决问题,给分
- 小弟我在程序中用到了一个下载的控件,可是编译成EXE文件后,在别的电脑上程序不能运行,怎么办?谢谢!
- 有谁知道电力系统关于线损计算的方法和公司,请指教,高分200
- 比较高的分!如何得到一个整形变量的地址?
- Progress Bar进度条控件问题,如何实现进度条(没有循环)?
- 关于在VB里编写COM+的初级问题!
但是怎么解决呢?
另外一个具体的例子参见
http://www.csdn.net/expert/topic/895/895649.xml?temp=7.825869E-02
问题正如你所说的,我看了你的解决方法,但是我用的是AxMSCommLib.AxMSComm的Output,Input两个属性(Property),而Delegate只能用于Sub和Function,怎么解决呢?
using System;
using System.Reflection;namespace MChen.LearnCSharp.Delegate {
public delegate void SetValue(int val);
public delegate int GetValue();
public class MainClass {
private int _val;
public int Value {
get { return _val; }
set { _val = value; }
}
public static void Main() {
MainClass mc = new MainClass(); SetValue sdel = (SetValue)MulticastDelegate.CreateDelegate(typeof(SetValue), mc, "set_Value");
sdel(5); //set_value
GetValue gdel = (GetValue)MulticastDelegate.CreateDelegate(typeof(GetValue), mc, "get_Value");
int ret = gdel(); //get_value
System.Console.WriteLine(ret);
}
}
}
MSCOMM控件有一个OUTPUT属性,用于我们发命令和数据,有个INPUT属性用于读返回的信息,这两个属性是在控件里的,我们没有办法改它.
看你的C#程序,好像要自己写属性的,也就是说自己能控制这个属性的代码,不知道我理解的对不对.
http://www.csdn.net/expert/topic/903/903896.xml?temp=.6861536
通过引用COM组件(或者使用tlbimp),你的Output在VB.NET里面应该是这样用的吧?
MSCOMM comm = New MSCOMM()
comm.Output = 1 '这里实际上是调用了set_Output函数那么只要能够把comm.Output = 1转换成一个delegate的调用就可以使用:
comm.Invoke(delegate)
从而避免线程问题了。.NET里面属性其实是有一对get/set函数组成的,比如Output,实际上是个函数:
Sub set_Output(value as System.Int32) '只写而delegate实际上是用于包装函数的,那么只要生成get/set函数的delegate问题就解决了。问题是C#/VB.NET不允许直接以函数的形式访问属性,所以我在上面使用了MulticastDelegate.CreateDelegate绕过这些限制。SetValue sdel = (SetValue)MulticastDelegate.CreateDelegate(typeof(SetValue), mc, "set_Value");
这一句实际上生成了一个用于为某个属性(mc.Value)符值的delegate,如果把这个属性换成comm.Output,你就可以用comm.Invoke(sdel)来安全的访问它了。
http://www.csdn.net/expert/topic/903/903896.xml?temp=.6861536