是否可以引用COM注册的DLL,然后在VBA代码中的构造函数中创建需要参数的对象?
我成功引用了在regasm
注册的Access 2013(64位)中的tlb,并且我设法创建了一个在构造函数中不需要参数的简单对象。
从我读到的,它不是。我现在面临重大的重构吗?
答案 0 :(得分:2)
它不一定是" major"。您只需要一个工厂方法,该方法获取构造对象所需的所有参数。例如:
public class Foo {
internal Foo(int arg1, string arg2) {
// etc...
}
// Other methods and properties
//...
}
public class FooFactory {
public Foo Create(int arg1, string arg2) {
return new Foo(arg1, arg2);
}
}
现在你只需在你的VBA代码中使用FooFactory.Create()。