I try to make a control type in 
[https://khchen.github.io/wNim/](https://khchen.github.io/wNim/), so I modified 
the examples coming with wNim.

The control will work like this: after click any of the 2 buttons on the frame, 
the frame will be closed, and a number will be returned to tell which button 
has been clicked.

However, the code will not be compiled due to 
    
    
    subclassing.nim(16, 13) Error: implicit object field construction requires 
a .partial object, but got wMyFrame:ObjectType
    
    
    Run

On the other hand, if I only write bt1 and bt2 without self. before them, I get 
    
    
    subclassing.nim(27, 5) Error: undeclared identifier: 'bt1'
    
    
    Run

I think I must misunderstand the type in nim, please correct me, thanks
    
    
    {.this: self.}
    import wNim
    
    type
        wMyFrame = ref object of wFrame
    
    proc final(self: wMyFrame) =
        wFrame(self).final()
    
    proc init(self: wMyFrame, title: string) =
        wFrame(self).init(title=title, size=(350, 200))
        center()
        
        var
            panel = Panel(self)
            bt1 = Button(panel, label="1", pos=(0, 0))
            bt2 = Button(panel, label="2", pos=(100, 0))
        
        self.wEvent_Close do (event: wEvent):
            let dlg = MessageDialog(self, "Do you really want to close this 
application?",
            "Confirm Exit", wOkCancel or wIconQuestion)
            
            if dlg.showModal() != wIdOk:
                event.veto()
    
    proc show(self: var wMyFrame): int {.discardable.} =
        bt1.wEvent_Button do (event: wEvent):
            self.endModal()
            self.close()
            
            return 1
        
        bt2.wEvent_Button do (event: wEvent):
            self.endModal()
            self.close()
            return 2
    
    proc MyFrame(title: string): wMyFrame {.inline.} =
        new(result, final)
        result.init(title)
    
    when isMainModule:
        let app = App()
        let frame = MyFrame("Hello World")
        
        var
            res = frame.show()
        app.mainLoop()
    
    
    
    Run

Reply via email to