将参数传递给另一个函数

时间:2015-06-08 22:00:38

标签: c++ node.js v8 node.js-addon

这里我将一个Argument分配给Handler:

Public Count As Integer ' Used to index the controls in my example

Sub addButton()
Dim P As Range: Set P = Selection
Dim B As Object
Dim S As String: S = CStr(Count) ' string representation of count

Set B = ActiveSheet.Buttons.Add(P.Left, P.Top, P.Width, P.Height)

With B
    .Caption = "Id#" & S
    .Name = "Id" & S
    .onAction = "'onAction " & Chr(34) & S & Chr(34) & "'"
End With

Count = Count + 1 ' Increase the counter

End Sub

Public Sub onAction(ByVal Index As String)
MsgBox "You Pressed Button #" & Index & "!", vbOKOnly, "Action"
End Sub

有效

但我想分配两个参数! 这就是我尝试做的原因:

const unsigned argc = 1;
v8::Local<v8::Value> argv[1] = { NanNew("hello world") };

NanMakeCallback(NanGetCurrentContext()->Global(), callHandle, argc, argv);

但后来我收到了这个错误:

 const unsigned argc = 2;
 v8::Local<v8::Value> argv[1] = { NanNew("hello world") };
 argv[2] = { NanNew("second argument") };

 NanMakeCallback(NanGetCurrentContext()->Global(), callbackHandle, argc, argv);

我错了什么?如何分配两个参数?感谢

2 个答案:

答案 0 :(得分:3)

您似乎正在创建一个大小为1的数组:

v8::Local<v8::Value> argv[1] = { NanNew("hello world") };

然后尝试将{ NanNew("second argument") };分配给索引为2的元素。这不会起作用。你的意思是这样的:

v8::Local<v8::Value> argv[2] = { NanNew("hello world"), NanNew("second arg") };

答案 1 :(得分:3)

您尝试分两步进行初始化。

int values[2] = { 0, 1 }; // OK: Array of two ints initialized with 0 and 1 respectively

int values[2] = { 0 }; // OK: Array of two ints, first value initialized with 0
values[1]= { 1 }; // Error: This is not an initialization

{}语法仅用于初始化数组。 (当然还有职能机构等)

在您的情况下,您可能想要这样做

v8::Local<v8::Value> argv[2] = { NanNew("hello world") , NanNew("second argument") };

请注意,您以前尝试创建一个只包含1个元素的数组,argv [1]并尝试访问第三个元素argv [2] = ...

索引从0开始,因此有效索引的范围从0到N-1。

相关问题