Forum: wxRuby Errors with TextCtrl.new!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tim M. (Guest)
on 2009-01-08 18:52
Here is my code:

require 'rubygems'
require 'wx'
include Wx

class GuiMudClientApp < App
  def on_init
    frame = Frame.new(nil, -1, "GMC: Incoming").show
    test = TextCtrl.new(frame, -1, "-----Mud stuff here-----",
Point.new(500, 500), Size.new(500, 500), TE_READONLY)
    test.append_text "Pfft!"
  end
end

nowai = GuiMudClientApp.new

nowai.main_loop

I get this error:

guimc.rb:8:in `new': Error initializing #<Wx::TextCtrl:0x74e3c0>
(TypeError)
 : Expected argument 1 of type wxWindow *, but got TrueClass true
  in SWIG method 'wxTextCtrl'
Correct parameters for Wxruby2::TextCtrl.new are:
:id => (Fixnum)
:value => (String)
:pos => (Wxruby2::Point)
:size => (Wxruby2::Size)
:style => (Fixnum)
:validator => (Wxruby2::Validator)
:name => (String)
  from guimc.rb:8:in `on_init'
  from guimc.rb:15:in `main_loop'
  from guimc.rb:15
Before, I could use a 'Frame' class as the parent window, but now its
having issues. I've followed it right off of the API docs. Any idea
whats wrong/how to fix it?

Thanks in advance,
     Zonbidesu
Tim M. (Guest)
on 2009-01-08 19:58
Addition: I'm on Mac OS 10.5(.9?)-- That's Leopard. Its a PPC, upgraded
PowerBook G4.
Alex F. (Guest)
on 2009-01-08 20:29
(Received via mailing list)
Hi

Tim M. wrote:
>     frame = Frame.new(nil, -1, "GMC: Incoming").show
>

You're assigning the return value of show() to the variable frame.
show() returns a boolean true/false.

>     test = TextCtrl.new(frame, -1, "-----Mud stuff here-----",
> Point.new(500, 500), Size.new(500, 500), TE_READONLY)

Now you're passing that variable containing 'true' as the first arg to
TextCtrl.new

> guimc.rb:8:in `new': Error initializing #<Wx::TextCtrl:0x74e3c0>
> (TypeError)
>  : Expected argument 1 of type wxWindow *, but got TrueClass true
>   in SWIG method 'wxTextCtrl'

so you get this error :)

> Before, I could use a 'Frame' class as the parent window, but now its
> having issues. I've followed it right off of the API docs. Any idea
> whats wrong/how to fix it?

frame = Wx::Frame.new(...)
frame.show
text = Wx::TextCtrl.new(frame, ...)

cheers
a
Tim M. (Guest)
on 2009-01-08 21:04
Ahahaha, thanks. I thought it was something silly like that...
This topic is locked and can not be replied to.