Forum: Ruby ruby tkentry tkvariable with class wrappers problem

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.
684d9992d72e5985bb177d5752ad80fc?d=identicon&s=25 Cristian Achim (branco)
on 2009-03-23 20:46
Attachment: chess_games_helper.rb (3 KB)
I try to create a tkEntry with a tkVariable attached in the class
startupinterface and create a callback to startupinterfacecontroller but
it doesn't work : it says that themember variable supposed to hold a
link to the tkVariable object is nil:nilClass when i try to call the
value member function

code is in attachement

any help appreciated
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 Hidetoshi NAGAI (Guest)
on 2009-03-23 21:21
(Received via mailing list)
From: Cristian Achim <cristiach@yahoo.com>
Subject: ruby tkentry tkvariable with class wrappers problem
Date: Tue, 24 Mar 2009 04:43:01 +0900
Message-ID: <34100fb324f5193a1b8567f60a34eea0@ruby-forum.com>
> it doesn't work : it says that themember variable supposed to hold a
> link to the tkVariable object is nil:nilClass when i try to call the
> value member function

Hmmm...
You may be misunderstanding about a block given to <widgetclass>.new.
# And, your code has a problem about accessing a TkVariable object.

---------------------------------------------------
   @files_lcoation_text=TkVariable.new
   @files_location_text=""
   @files_location_entry=TkEntry.new(tk_root){
     textvariable @files_location_text
   }.grid("row"=>0 , "column"=>1)
   @files_location_text="tada"
---------------------------------------------------

Such block is evaluated with "instance_eval".
That is, at internal of the block, "self" is the widget created by
"new" method. So, @files_location_text in the block is a instance
variable of the entry widget.

There are two ways to avoid this problem.
The one is to use a local variable.
And another is to use a Hash argument.

-----<case.1>----------------------------------------------
   @files_lcoation_text = txt_var = TkVariable.new("")
   @files_location_entry=TkEntry.new(tk_root){
     textvariable txt_var
   }.grid("row"=>0 , "column"=>1)
   @files_location_text.value = "tada"
-----------------------------------------------------------

-----<case.2>----------------------------------------------
   @files_lcoation_text = TkVariable.new("")
   @files_location_entry=TkEntry.new(tk_root,
:textvariable=>@files_lcoation_text).grid(:row=>0 , :column=>1)
   @files_location_text.value = "tada"
-----------------------------------------------------------

Please take attention to a scope of a variable.
684d9992d72e5985bb177d5752ad80fc?d=identicon&s=25 Cristian Achim (branco)
on 2009-03-23 22:07
problem solved ; thanks for the help
684d9992d72e5985bb177d5752ad80fc?d=identicon&s=25 Cristian Achim (branco)
on 2009-03-23 23:03
Attachment: chess_games_helper.rb (3 KB)
the fix is good but i hit another problem

when I try to change the value of the tkvariable member variable with
the value member function of tkvariable it doesn't work : it says
nil:NilClass when pressing the button change_entry_text

I try to change the value of the initial entry/tkvariable by using the
value of a new one or possibly the value supplied by any external class
that has a reference

new code version is attached
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 Hidetoshi NAGAI (Guest)
on 2009-03-24 03:42
(Received via mailing list)
From: Cristian Achim <cristiach@yahoo.com>
Subject: Re: ruby tkentry tkvariable with class wrappers problem
Date: Tue, 24 Mar 2009 07:00:24 +0900
Message-ID: <81d191cc09ee5a2117fba8201cbbbfe7@ruby-forum.com>
> when I try to change the value of the tkvariable member variable with
> the value member function of tkvariable it doesn't work : it says
> nil:NilClass when pressing the button change_entry_text

It's a typo.

--- chess_games_helper.rb.orig  2009-03-24 11:38:46.000000000 +0900
+++ chess_games_helper.rb       2009-03-24 11:40:03.000000000 +0900
@@ -51,7 +51,7 @@
                files_location_entry_d.insert('end' , "data files
location")
                files_location_entry_d.state="disabled"

-               @files_lcoation_text=txt_var=TkVariable.new
+               @files_location_text=txt_var=TkVariable.new

                new_txt=TkVariable.new
                files_location_entry=TkEntry.new(tk_root){
684d9992d72e5985bb177d5752ad80fc?d=identicon&s=25 Cristian Achim (branco)
on 2009-03-24 04:30
that fixed it again hope i'll be more carefull next time and not post
typo questions
This topic is locked and can not be replied to.