GetRef to capture methods?

I just opened a VBScript GetRef function that gets a reference to a function called its argument. Is there a way to get a reference to a method this way? I have a hunch that VBScript does not offer the binding complexity needed for this, but that would be nice.

+4
source share
2 answers

No, GetRef does not support class methods.

+2
source

There is a workaround for this, see my answer here

Here is the full sample.

 Const forReading = 1, forWriting = 2, forAppending = 8, CreateFile = True Set my_obj = CreateObject("Scripting.FileSystemObject").OpenTextFile("c:\temp\test.txt", forWriting, CreateFile) Function my_function(my_obj, method, text) command = "my_obj." & method & " """ & text & """" ExecuteGlobal command End Function 'make a reference to our function Set proc = GetRef("my_function") 'and call it with parameters, the first being the method invoked Call proc(my_obj, "WriteLine", "testing") 'cleanup' my_obj.Close Set my_obj = Nothing 
0
source

Source: https://habr.com/ru/post/1312113/


All Articles