In my situation, I translate a python code into nim 
    
    
    # I am cli.py
    
    def checkHeading():
        word.Selection.HomeKey(Unit=win32com.client.constants.wdStory,
            Extend=win32com.client.constants.wdMove)
        do some check on Heading, then display message
    
    
    def checkPunctation():
        word.Selection.HomeKey(Unit=win32com.client.constants.wdStory,
            Extend=win32com.client.constants.wdMove)
        do some check on punctaion, then display message
    
    def check(fn):
        global word
        word = win32com.client.gencache.EnsureDispatch("Word.Application")
        
        word.Documents.Open(FileName=fn, ReadOnly=True)
        
        checkHeading()
        checkPunctation()
    
    if __name__ == '__main__':
        check(r'c:\test.doc')
    
    
    
    Run

As you can see, there is global variant word in function check, and this 
variant can be used in other functions

So I can write the GUI app by using cli.py as module 
    
    
    there is button to choose and open file
    then redirect stdout to gui text-control
    
    
    Run

how ever, in nim even I use 
    
    
    var word {.**global**.} = CreateObject("Word.Application")
    
    
    Run

in proc check, I still get R:CheckIt.nim(709, 5) Error: undeclared identifier: 
'word'

so is there real python-like global solution except 
    
    
    proc checkHeading() =
        word.Selection.HomeKey(...)
        do some check on Heading, then display message
    
    
    proc checkPunctation() =
        word.Selection.HomeKey(...)
        do some check on punctaion, then display message
    
    proc check(fn):
        word.Documents.Open(fn, True)
        
        checkHeading()
        checkPunctation()
    
    var word = CreateObject("Word.Application")
    
    
    Run

Reply via email to