Forums

Issues getting OpenFileDialog to work

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

Issues getting OpenFileDialog to work

Postby torial » Sun Jan 24, 2010 12:07 pm

When I compile and run the following code, and select the "..." button, it gives a message box (my test to confirm the event fired) but then hangs when trying to show the dialog.

Can you pass on any pointers as to what I'm doing wrong or missing? The original goal was to try and learn Cobra by implementing http://cobra-language.com/trac/cobra/wiki/PortingC ... but I didn't get far :-/

Thanks,

Sean
Code: Select all

use System.Windows.Forms from "System.Windows.Forms"

class CSharp2Cobra inherits Form
   var _txtFile as TextBox
   var _lblFile as Label
   var _btnBrowse as Button
   var _btnConvert as Button
   var _panel as FlowLayoutPanel

   cue init
       base.init
       .text = 'C# to Cobra Converter'
       _panel = FlowLayoutPanel(parent=this, dock=DockStyle.Fill, flowDirection=FlowDirection.TopDown)
       _lblFile = Label(parent=_panel, autoSize=true,text='File Name:')
       _txtFile = TextBox(parent=_panel, width=300, text='')
       _btnBrowse = Button(parent=_panel, autoSize=true, text='...', tag=1)
       listen _btnBrowse.click, ref .browseFile
       _btnConvert = Button(parent=_panel, autoSize=true, text='Two', tag=2)
       listen _btnConvert.click, ref .handleClick

   def browseFile(sender, args as EventArgs)
       MessageBox.show(this, 'You clicked [sender.text]/[sender.tag]', 'Click')
       dlg = OpenFileDialog()
       #dlg.filter = "C# files|*.cs"
       #dlg.filterIndex = 1
       result = dlg.showDialog
       #if dlg.showDialog == DialogResult.OK
       #    _txtFile.text = dlg.fileName


   def handleClick(sender, args as EventArgs)
       MessageBox.show(this, 'You clicked [sender.text]/[sender.tag]', 'Click')

class Program

   def main is shared
       Application.run(CSharp2Cobra())
torial
 
Posts: 229
Location: IA

Re: Issues getting OpenFileDialog to work

Postby Charles » Mon Jan 25, 2010 7:49 pm

It works on my system. I click OK on the message box and then the open file dialog appears which I cancel out of.

I'm using the latest Cobra from source.

My system is Windows XP Pro SP 3.

What version of Cobra are you using? Does the C# code work? What if you compile with -turbo ?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Issues getting OpenFileDialog to work

Postby torial » Mon Jan 25, 2010 8:47 pm

Chuck wrote:It works on my system. I click OK on the message box and then the open file dialog appears which I cancel out of.

I'm using the latest Cobra from source.

My system is Windows XP Pro SP 3.

What version of Cobra are you using? Does the C# code work? What if you compile with -turbo ?


Thanks for checking it out. I will look into a C# variant to see if it works.

I used the latest source repository (the unzipped folder was Cobra-Informal-Release-2009-06-09), and ran the install-from-workspace.bat.

Possible variants in my environment: I've got VS 2008 installed, .Net 3.5 SP1, and I'm not sure what version of .Net 2.0 I have. The OS is Win2008 Server.

Oh -- I just thought of something to try as well -- permissions! I will look into that and report back. It may be a few days though.
torial
 
Posts: 229
Location: IA

Re: Issues getting OpenFileDialog to work

Postby torial » Mon Jan 25, 2010 8:48 pm

torial wrote:
Chuck wrote:Oh -- I just thought of something to try as well -- permissions! I will look into that and report back. It may be a few days though.


Permissions were not the issue :-/ I ran the program as administrator and did it still hung. I'll try the C# implementation in the next few days.
torial
 
Posts: 229
Location: IA

Re: Issues getting OpenFileDialog to work

Postby Charles » Mon Jan 25, 2010 11:48 pm

Cobra-Informal-Release-2009-06-09 is the last informal release. The latest source is retrieved with subversion. See:

http://cobra-language.com/trac/cobra/wiki/HowToInstallFromSource

I also have VS 2008 and .NET 3.5 installed.

It will be very informative if a C# version works and if it works if you mark it as targeting .NET 2.0 vs 3.5.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Issues getting OpenFileDialog to work

Postby torial » Tue Jan 26, 2010 11:14 am

Chuck wrote:Cobra-Informal-Release-2009-06-09 is the last informal release. The latest source is retrieved with subversion. See:

http://cobra-language.com/trac/cobra/wiki/HowToInstallFromSource

I also have VS 2008 and .NET 3.5 installed.

It will be very informative if a C# version works and if it works if you mark it as targeting .NET 2.0 vs 3.5.


I haven't tried it with the latest from the repository -- but I did run into an issue (regardless of 2.0/3.5) with C#. I will have to look into this further (didn't try the turbo, since C# replicates it).


ERROR reported in Visual Studio: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.

(NOTE, I get this irrespective of running in Debug or Release w/ VS). I will look at what I need, perhaps the STA attribute?
torial
 
Posts: 229
Location: IA

Re: Issues getting OpenFileDialog to work

Postby torial » Tue Jan 26, 2010 12:55 pm

What is the syntax for applying an attribute to a function? Is it VB inspired, C#, of Python?
torial
 
Posts: 229
Location: IA

Re: Issues getting OpenFileDialog to work

Postby Charles » Tue Jan 26, 2010 2:48 pm

class Foo
def main is shared
has STAThread
Program().run

"... has ATTR"

See http://cobra-language.com/how-to/WPF/ for an example.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Issues getting OpenFileDialog to work

Postby torial » Tue Jan 26, 2010 3:13 pm

Chuck wrote:
class Foo
def main is shared
has STAThread
Program().run

"... has ATTR"

See http://cobra-language.com/how-to/WPF/ for an example.


That attribute fixed it, thanks!
torial
 
Posts: 229
Location: IA

Re: Issues getting OpenFileDialog to work

Postby Charles » Tue Jan 26, 2010 5:58 pm

Excellent.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 47 guests