Interaction.CallByName(Object, String, CallType, Object[]) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menjalankan metode pada objek, atau mengatur atau mengembalikan properti pada objek.
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
Parameter
- ObjectRef
- Object
Wajib diisi.
Object. Penunjuk ke objek yang mengekspos properti atau metode.
- ProcName
- String
Wajib diisi.
String. Ekspresi string yang berisi nama properti atau metode pada objek .
- UseCallType
- CallType
Wajib diisi. Anggota enumerasi jenis CallType yang mewakili jenis prosedur yang dipanggil. Nilai CallType dapat berupa Method, Get, atau Set.
- Args
- Object[]
Opsional.
ParamArray. Array parameter yang berisi argumen yang akan diteruskan ke properti atau metode yang dipanggil.
Mengembalikan
Menjalankan metode pada objek, atau mengatur atau mengembalikan properti pada objek.
Pengecualian
Nilai tidak valid UseCallType ; harus Method, , Getatau Set.
Contoh
Dalam contoh berikut, baris pertama menggunakan CallByName untuk mengatur Text properti kotak teks, baris kedua mengambil nilai Text properti , dan baris ketiga memanggil Move metode untuk memindahkan kotak teks.
' 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
Contoh berikutnya menggunakan CallByName fungsi untuk memanggil Add metode dan Item dari objek koleksi.
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
Keterangan
Fungsi CallByName ini digunakan saat runtime untuk mendapatkan properti, mengatur properti, atau memanggil metode .