I’m selling some code. So I want to take everything out of the existing code that is private like my SendGrid password. I can check if a method is available. But can anyone remind me how to use this with a pragma?
Or is there a better solution?
Existing code:
if HasMethod(Globals, "GetMore") then socket1.username = Globals.GetMore
[code]Private Function HasMethod(theObject as Object, methodName as String) As Boolean
'check if a class has a specific Method
dim theMethods(-1) as MethodInfo = theObject.Methods
for Each currentMethod as Introspection.MethodInfo in theMethods
dim theName as String = currentMethod.Name
if theName = methodName then Return true
next
End Function[/code]
If the method isn’t available then this code won’t compile as Globals.GetMore doesn’t exist. Instead return the MethodInfo and call it with that
[code]Private Function HasMethod(theObject as Object, methodName as String) As Introspection.MethodInfo
dim theMethods(-1) as MethodInfo = theObject.Methods
for Each currentMethod as Introspection.MethodInfo in theMethods
dim theName as String = currentMethod.Name
if theName = methodName then Return currentMethod
next
End Function
dim m As Introspection.MethodInfo = HasMethod(Globals, “GetMore”)
if m <> nil then socket1.username = m.Invoke(Globals)[/code]