Forums

Namespace collision?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Namespace collision?

Postby arisawa » Tue Dec 02, 2008 10:38 am

Because nature and Windows Forms DLL came to be referred to, I became convenient.
However, does not a namespace collide with WPF DLL?
arisawa
 
Posts: 51

Re: Namespace collision?

Postby Charles » Tue Dec 02, 2008 10:59 am

I'm not exactly sure what you are asking, but I'll try to help.

If you have two classes with the same name, but in different namespaces, then you can access them by their fully qualified name:
# untested
use System.Windows.Controls
use System.Windows.Forms

class X
def main is shared
print System.Windows.Controls.Button
print System.Windows.Forms.Button

Does that help?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Namespace collision?

Postby arisawa » Tue Dec 02, 2008 1:40 pm

Thank you.

However, it was my misunderstanding with most.
Please forget WPF.

Can not compile the following def.
The former cobra was possible.
...
def onClick(sender as Object, args as EventArgs)
MessageBox.show('You clicked Button', 'Click')
...
arisawa
 
Posts: 51

Re: Namespace collision?

Postby Charles » Tue Dec 02, 2008 6:35 pm

(1) Be sure to use Cobra from source: HowToInstallFromSource

(2) This works for me:
use System.Windows.Forms

class Program

def main is shared
Program().run

def run
b = Button(text='Click me')
listen b.click, ref .onClick

def onClick(sender as Object, args as EventArgs)
MessageBox.show('You clicked Button', 'Click')
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Namespace collision?

Postby arisawa » Wed Dec 03, 2008 12:11 am

Umm...
The installation seems to have succeeded.
There is still a problem.
Nothing is displayed even if I can compile it in the shown example.

The template which I use is the following cords which are near to 'HowTo/380-WinForms.cobra'.
use System.Windows.Forms
use System.Drawing

class MyForm
inherits Form
def init
.text = 'Click'
btn = Button()
btn.parent = this
listen btn.click, ref .onClick

def onClick(sender as Object, args as EventArgs)
MessageBox.show('You clicked Button', 'Click')

class Program
def main is shared
Application.run(MyForm())

When a name of event handler is 'onClick' then, I get an error.
error: Could not find an overload for "onClick" with zero arguments.

When it is another name, I do not seem to have any problem. (e.g. btn_onClick)
arisawa
 
Posts: 51

Re: Namespace collision?

Postby Charles » Wed Dec 03, 2008 2:05 am

The first time I ran this on Windows, it came up pretty quick. But on Mono 2.0 on Mac, my hard drive churned for 3 minutes before the the window came up. On subsequent launches on Mono, the program came up quickly. So the first Mono launch requires patience.

Regarding the name "onClick", this was a bug in Cobra regarding "listen" and overloaded methods. There is already an "onClick" in an ancestor class which caused this bug to be revealed. I have fixed the bug so now you can "svn upd" and install again.

Also, you can write this kind of code for convenience if you like:
b = Button(text='Click this button', parent=this)
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Namespace collision?

Postby arisawa » Wed Dec 03, 2008 10:44 pm

It worked well, this time. :)

How to write that does not appoint a type 'sender' is convenient.
It was usable in wx.NET, and a trouble of that place was settled, too.

Thank you.
arisawa
 
Posts: 51


Return to Discussion

Who is online

Users browsing this forum: No registered users and 22 guests