Interaction.CallByName(Object, String, CallType, Object[]) 方法

定义

执行对象的方法,或者设置或返回对象的属性。Executes a method on an object, or sets or returns a property on an object.

public:
 static System::Object ^ CallByName(System::Object ^ ObjectRef, System::String ^ ProcName, Microsoft::VisualBasic::CallType UseCallType, ... cli::array <System::Object ^> ^ Args);
public static object? CallByName (object? ObjectRef, string ProcName, Microsoft.VisualBasic.CallType UseCallType, params object?[] Args);
public static object CallByName (object ObjectRef, string ProcName, Microsoft.VisualBasic.CallType UseCallType, params object[] Args);
static member CallByName : obj * string * Microsoft.VisualBasic.CallType * obj[] -> obj
Public Function CallByName (ObjectRef As Object, ProcName As String, UseCallType As CallType, ParamArray Args As Object()) As Object

参数

ObjectRef
Object

必需。Required. Object.Object. 一个指向公开属性或方法的对象的指针。A pointer to the object exposing the property or method.

ProcName
String

必需。Required. String.String. 一个字符串表达式,包含对象的属性或方法的名称。A string expression containing the name of the property or method on the object.

UseCallType
CallType

必需。Required. 类型 CallType 的一个枚举成员,它表示正在被调用的过程的类型。An enumeration member of type CallType representing the type of procedure being called. CallType 的值可以是 MethodGetSetThe value of CallType can be Method, Get, or Set.

Args
Object[]

可选。Optional. ParamArray.ParamArray. 一个形参数组,包含要传递给正在调用的属性或方法的实参。A parameter array containing the arguments to be passed to the property or method being called.

返回

Object

执行对象的方法,或者设置或返回对象的属性。Executes a method on an object, or sets or returns a property on an object.

例外

无效 UseCallType 值;必须为 MethodGetSetInvalid UseCallType value; must be Method, Get, or Set.

示例

在下面的示例中,第一行使用 CallByName 设置文本框的 Text 属性,第二行检索属性的值 Text ,第三行调用 Move 方法来移动文本框。In the following example, the first line uses CallByName to set the Text property of a text box, the second line retrieves the value of the Text property, and the third line invokes the Move method to move the text box.

' Imports statements must be at the top of a module.
Imports Microsoft.VisualBasic.CallType
Sub TestCallByName1()
    'Set a property.
    CallByName(TextBox1, "Text", CallType.Set, "New Text")

    'Retrieve the value of a property.
    MsgBox(CallByName(TextBox1, "Text", CallType.Get))

    'Call a method.
    CallByName(TextBox1, "Hide", CallType.Method)
End Sub

下一个示例使用 CallByName 函数调用 Add 集合对象的和 Item 方法。The next example uses the CallByName function to invoke the Add and Item methods of a collection object.

Public Sub TestCallByName2()
    Dim col As New Collection()

    'Store the string "Item One" in a collection by 
    'calling the Add method.
    CallByName(col, "Add", CallType.Method, "Item One")

    'Retrieve the first entry from the collection using the 
    'Item property and display it using MsgBox().
    MsgBox(CallByName(col, "Item", CallType.Get, 1))
End Sub

注解

CallByName函数在运行时用于获取属性、设置属性或调用方法。The CallByName function is used at runtime to get a property, set a property, or invoke a method.

适用于

另请参阅