Skip to main content
Question

Call a method from a VAR.

  • December 15, 2025
  • 2 replies
  • 37 views

ajSauro

I think that no, but…

Can I do something like that?:

       77 lsMethod string.


           Move 'gabert' to lsMethod
           Invoke Classes lsMethod returning QuebraGalho 
 

Hugs.

Antonio João

Visual COBO + Visual Studio.

2 replies

Chris Glazier
Forum|alt.badge.img+3

You can do this using Reflection in .NET.

Something like this:

      $set ilusing"System"
$set ilusing"System.Reflection"
program-id. Program1 as "testdynamicinvoke.Program1".
data division.
working-storage section.
01 methodname string value "AddIt".
01 propname string value "myprop".
procedure division.
declare myobj as type MyClass = new MyClass
declare addmethod as type MethodInfo = myobj::GetType::GetMethod(methodname)
declare num1 as binary-long = 10
declare num2 as binary-long = 5
declare myparams = table of object (num1, num2)
declare result as binary-long = addmethod::Invoke(myobj, myparams) as binary-long
display "result = " result

*> set a property using reflection
declare mytype = myobj::GetType
declare myprop as type PropertyInfo = mytype::GetProperty(propname)
invoke myprop::SetValue(myobj, "Chris")
display myobj::myprop
goback.

end program Program1.
class-id MyClass.
working-storage section.
01 myprop string property public.
method-id AddIt public.
local-storage section.
procedure division using by value lnk-num1 as binary-long lnk-num2 as binary-long
returning result as binary-long.

compute result = lnk-num1 + lnk-num2

goback.
end method.

end class.

 


ajSauro
  • Author
  • New Participant
  • December 17, 2025

Man, it worked.

That's exactly what I needed.

I searched for silver and found gold; the example of changing a property using reflection also worked for me.

Thank you.

 

Antonio João

Visual COBOL + Visual Studio