[FxRuby] Question on FXDataTarget

I’m using FOX via FxRuby and I’m trying to get FXDataTarget going. If I
wrap a local variable in an FXDataTarget and then put a FXTextField around
that, everything seems to work fine. IOW, this works

@fooDt = FXDataTarget.new(0)
@foo_input = FXTextField.new(self, 5, @fooDt, FXDataTarget::ID_VALUE, …)

and then in a button’s method

@fooDt.value = 99

the result is that the text field get’s updated like it should. But what if
I have an object whose members I want to connect to text fields? IOW, I
have this class

class Foo
attr_accessor :bar
end

@foo = Foo.new
@fooDt = FXDataTarget.new(@foo.bar)
@foo_input = FXTextField.new(self, 5, @fooDt, FXDataTarget::ID_VALUE, …)

and then in a button’s method

@foo.bar = 99

the textfield does not get updated, even though the attribute of the object
has been updated.

Am I doing something wrong here?

Note: I posted this to both foxgui-users and ruby-talk since it spans
both…

Thanks,
Joey

···


Joey Gibson wrote:

I’m using FOX via FxRuby and I’m trying to get FXDataTarget going. If I
wrap a local variable in an FXDataTarget and then put a FXTextField around
that, everything seems to work fine. IOW, this works

@fooDt = FXDataTarget.new(0)
@foo_input = FXTextField.new(self, 5, @fooDt, FXDataTarget::ID_VALUE, …)

and then in a button’s method

@fooDt.value = 99

the result is that the text field get’s updated like it should. But what if
I have an object whose members I want to connect to text fields? IOW, I
have this class

class Foo
attr_accessor :bar
end

@foo = Foo.new
@fooDt = FXDataTarget.new(@foo.bar)
@foo_input = FXTextField.new(self, 5, @fooDt, FXDataTarget::ID_VALUE, …)

and then in a button’s method

@foo.bar = 99

the textfield does not get updated, even though the attribute of the object
has been updated.

Am I doing something wrong here?

The only thing you’re doing wrong is attributing more power to the
FXDataTarget than it actually has :wink:

An FXDataTarget is a special kind of object that acts as a wrapper
around some other object (its value). As you’ve already discovered, you
can get or set the value of this wrapped-up object via the
FXDataTarget#value() and FXDataTarget#value=() accessor methods, e.g.

 fooDt = FXDataTarget.new(0)
 fooDt.value = 99
 theValue = fooDt.value

When a widget like FXTextField interacts with a data target, it
(indirectly) uses these accessors to get and set the value of the data
target.

But when you initialize a data target with some value, e.g.

 fooDt = FXDataTarget.new(@foo.bar)

it just sets the value of its wrapped-up object to the current value of
@foo.bar. In other words, both @foo.bar and fooDt.value are now
references to the same object. But – and this is the important part –
there’s no way for the data target to change which object @foo.bar
points to.

I’m trying to do simple keyboard input:

a = ""
a = gets
puts a

I’m running Ruby 1.6.7, under Win 98 SE.

When I type the first letter, I receive the message

[bug] Segmentation Fault.

I’ve removed Ruby and reinstalled it several times, with consistent
failures.

  1. What do I need to do?

  2. There MUST be a better way. What is it?

Leon

Joey Gibson wrote:

I’m using FOX via FxRuby and I’m trying to get FXDataTarget going. If I
wrap a local variable in an FXDataTarget and then put a FXTextField around
that, everything seems to work fine. IOW, this works

I’ve been working on some extensions to help with this kind of problem.
I wasn’t going to release it for a week or two, but since it might help
you, I’ve gona ahead and packaged up an alpha version. Docs and tests
are sketchy, but there are some examples.

Look for an announcement for FoxTails.

Thanks Lyle. I was assuming that it worked like a Smalltalk adaptor which
could update and receive updates from (sortof) nested properties.

Joey

···

On Wed, 15 Jan 2003 04:35:31 +0900, Lyle Johnson lyle@users.sourceforge.net wrote:

The only thing you’re doing wrong is attributing more power to the
FXDataTarget than it actually has :wink:

Very odd. I’ve run Ruby on 98SE for ages and
never saw this happen in any version.

Perhaps go to 1.6.8 or even later. (I personally
find the development versions to be pretty stable.)

Hal

···

----- Original Message -----
From: “Dr. Leon Stevens” stevensl@lincolnu.edu
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, January 14, 2003 2:08 PM
Subject: Segmentation fault on gets

I’m trying to do simple keyboard input:

a = “”
a = gets
puts a

I’m running Ruby 1.6.7, under Win 98 SE.

When I type the first letter, I receive the message

[bug] Segmentation Fault.

I’ve removed Ruby and reinstalled it several times, with consistent
failures.

  1. What do I need to do?

  2. There MUST be a better way. What is it?

I know that I get this error if I run it in SciTe 1.41 on Windows XP:

>ruby tst.rb
tst.rb:2:in `gets': Bad file descriptor (Errno::EBADF)
 from tst.rb:2
What is your name?>Exit code: 1

But I have ** always ** got it to work in command shell (at the C:>
prompt).

On your machine, what does the output of “ruby -v” look like, Leon ?

– shanko

“Dr. Leon Stevens” stevensl@lincolnu.edu wrote in message
news:NFBBKIJCMLMMEMOCCCDLCEKJCCAA.stevensl@lincolnu.edu…

···

I’m trying to do simple keyboard input:

a = “”
a = gets
puts a

I’m running Ruby 1.6.7, under Win 98 SE.

When I type the first letter, I receive the message

[bug] Segmentation Fault.

I’ve removed Ruby and reinstalled it several times, with consistent
failures.

  1. What do I need to do?

  2. There MUST be a better way. What is it?

Leon

Joey Gibson wrote:

Thanks Lyle. I was assuming that it worked like a Smalltalk adaptor which
could update and receive updates from (sortof) nested properties.

I am not a Smalltalk programmer; are there any online references you
could point me to that describe how these adaptors work? It might
inspire me to beef up FXDataTarget’s capabilities a bit, if there’s any
good way to do so.

ruby 1.6.8 (2002-12-24) [i586-mswin32]

I’m using scite 1.41.

I decided to try 1.6.8, hoping that it would behave differently.

At present, I have great suspicions about my machine, and plan to try it on
a couple of others.

Leon

···

-----Original Message-----
From: Shashank Date [mailto:sdate@kc.rr.com]
Sent: Tuesday, January 14, 2003 7:37 PM
To: ruby-talk ML
Subject: Re: Segmentation fault on gets

I know that I get this error if I run it in SciTe 1.41 on Windows XP:

>ruby tst.rb
tst.rb:2:in `gets': Bad file descriptor (Errno::EBADF)
 from tst.rb:2
What is your name?>Exit code: 1

But I have ** always ** got it to work in command shell (at the C:>
prompt).

On your machine, what does the output of “ruby -v” look like, Leon ?

– shanko

“Dr. Leon Stevens” stevensl@lincolnu.edu wrote in message
news:NFBBKIJCMLMMEMOCCCDLCEKJCCAA.stevensl@lincolnu.edu…

I’m trying to do simple keyboard input:

a = “”
a = gets
puts a

I’m running Ruby 1.6.7, under Win 98 SE.

When I type the first letter, I receive the message

[bug] Segmentation Fault.

I’ve removed Ruby and reinstalled it several times, with consistent
failures.

  1. What do I need to do?

  2. There MUST be a better way. What is it?

Leon