From: Tomas Na Date: 2009-04-05T04:02:45+09:00 Subject: Function as Parameter? I am new to Ruby so I don't know a great deal about the language, but what I am trying to do is the following: Create an application that will display a login form. The user enters their details and then that form disappears and they are taken to a different form containing a canvas (which will have images drawn on it eventually). I don't want to create both forms and set their visibility, as the invisible form will still be loaded in memory which is a waste. They I thought of getting around this is to start the program in a "form manager" style class, which then has the ability to create either of the two forms. The trouble I am facing then, is that the button the form has to pass back the username and password to the form manager, so that when the Login form closes it may construct a Canvas from and pass the details. To make this happen I figured I would pass in a callback. Searching around, I couldn't find a lot of info about callbacks, but I was reading about passing a symbol. I may have got this wrong, but it looks like if I pass in :function_name then it will be a symbol that I can call. Well I tried it like this: def TestFunc() puts 'Test' end xaApp = FXApp.new LoginForm.new(xaApp,'TestApp',:TestCallback) xaApp.create xaApp.run In my "Form Manager", and in my LoginForm's initialize I have: def initialize(anApp,sTitle,aCallback) super(anApp, sTitle,:opts => DECOR_ALL, :width => 165, :height => 250) FXLabel.new(self,"Username:", nil, JUSTIFY_LEFT|LAYOUT_FILL_X) FXTextField.new(self, 23, nil, 0, TEXTFIELD_NORMAL) FXLabel.new(self,"Password:", nil, JUSTIFY_LEFT|LAYOUT_FILL_X) FXTextField.new(self, 23, nil, 0, TEXTFIELD_NORMAL) xbButton = FXButton.new(self,"Log in",:opts => FRAME_RAISED|LAYOUT_CENTER_X|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT,:width => 80, :height => 20) xbButton.connect(SEL_COMMAND,aCallback) end This runs okay until I click the button, at which point I get the error: C:\Users\Tomas\Desktop\Ruby>ruby testapp.rb c:/ruby/lib/ruby/gems/1.8/gems/fxruby-1.6.12-mswin32/lib/fox16/responder2.rb:55: in `onHandleMsg': undefined method `call' for :TestCallback:Symbol (NoMethodErro r) from testapp.rb:14:in `run' from testapp.rb:14 If I can get this working, then I will be able to move on to trying to get it working with passing the two string parameters in as well. Can someone please explain to me how I can call the function in my main code when the button is clicked in the form? -- Posted via http://www.ruby-forum.com/.