本文介绍了如何创建PSafeArray类型的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建PSafeArray类型的参数?
How to create a parameter of type PSafeArray?
我从C#COM库中遇到以下错误:
I take the following error from C# COM library:
SafeArray with range 65262 transfered to the method that requires array with range 1
Delphi XE2
应该使用带有参数PSafeArray类型的 Generated RIDL
类型库调用 C#COM库
过程.
Delphi XE2
should call C# COM library
procedure using Generated RIDL
type-library with a parameter of type PSafeArray.
Delphi XE2代码:
Delphi XE2 code:
function GetObjects: PSafeArray;
var
aObjects: Variant;
begin
aObjects := VarArrayCreate([0, 2], varVariant);
aObjects[0] := ADOConnection.ConnectionObject;
aObjects[1] := CashConnection;
aObjects[2] := Self as IDispatch;
Result := PSafeArray(TVarData(aObjects).VArray);
end;
ICompiler.Execute('MainNameSpace', 'MainClass', 'MainMethod', GetObjects);
C#COM库代码:
void Execute(string Namespace, string ClassName, string MethodName, Object[] Objects);
void ICSCompiler.Execute(string Namespace, string ClassName, string MethodName, Object[] Objects)
{
System.Type _type = cr.CompiledAssembly.GetType(Namespace + "." + ClassName);
System.Object obj = Activator.CreateInstance(_type);
System.Reflection.MethodInfo mi = obj.GetType().GetMethod(MethodName);
mi.Invoke(obj, new Object[] { Objects });
}
生成的RIDL代码:
HRESULT _stdcall Execute([in] BSTR Namespace, [in] BSTR ClassName, [in] BSTR MethodName, [in] SAFEARRAY(VARIANT) Objects);
推荐答案
我能记住的第一件事是 SafeArrayCreate
.看看' PSafeArray的奥秘'
the first thing i can remember is SafeArrayCreate
.have a look at 'mysteries of PSafeArray'
这篇关于如何创建PSafeArray类型的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!