Hi all, Thanks a lot for com library in Nim. Its fantasctic. I like the way the com behaves in Nim. Its just like in any scripting language. But i would like to know that how can i wrap these com code inside a function and how can i return a com object. Please see this code.
import winim/com
comScript: # Is this line needed or not ? I dont know.
proc GetExcelObject() = # Used ": variant" here, but failed. And used ": com" here. That also failed.
try:
var obj = GetObject("", "Excel.Application")
echo obj.ActiveWindow.Caption # Just for testing. Will delete later
#return obj # I want to return this Excel object from this proc but don't know how
except :
echo "Excel is not Opened"
#End try
#End Proc
#End comScript
This is the working model of my excel object getting proc. But i want this proc return a com object. I would like to create some more procs to get the ExcelSheet object, WorkBook object etc. I know dont about COM and Windows in general, but if you dont put a return type it does not return.
Try proc GetExcelObject(): auto = ?
Not tested, but how about
import winim/com
proc GetExcelObject*(): com =
result = nil # should be newCom() ??
try:
result = GetObject("", "Excel.Application")
echo result.ActiveWindow.Caption # Just for testing. Will delete later
except :
echo "Excel is not Opened"
jlp765's code works for me. Can you post your error message?
import winim/com
proc GetExcelObject*(): com =
result = nil # should be newCom() ??
try:
result = GetObject("", "Excel.Application")
echo result.ActiveWindow.Caption # Just for testing. Will delete later
except :
echo "Excel is not Opened"
discard GetExcelObject()