<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to 47: ReflectObject loses command</title><link>https://sourceforge.net/p/tcljava/bugs/47/</link><description>Recent changes to 47: ReflectObject loses command</description><atom:link href="https://sourceforge.net/p/tcljava/bugs/47/feed.rss" rel="self"/><language>en</language><lastBuildDate>Mon, 25 Aug 2008 04:53:10 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/tcljava/bugs/47/feed.rss" rel="self" type="application/rss+xml"/><item><title>ReflectObject loses command</title><link>https://sourceforge.net/p/tcljava/bugs/47/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;There seems to be a situation where a Java Object command is&lt;br /&gt;
deleted from the interpreter, but the object still resides&lt;br /&gt;
in the interp.reflectObjTable.  This patch causes the&lt;br /&gt;
java object command to be re-created if the command no&lt;br /&gt;
longer exists.&lt;/p&gt;
&lt;p&gt;Note that this bug is exposed when using Incr Tcl, I'm not sure&lt;br /&gt;
if there are other cases where the bug is exposed.&lt;/p&gt;
&lt;p&gt;Also note: my first attempt at a patch simply invoked&lt;br /&gt;
interp.createCommand() if the command was missing, but&lt;br /&gt;
that yielded "reflected object is no longer valid" when used (from the&lt;br /&gt;
cmdProc() method.)&lt;/p&gt;
&lt;p&gt;---------------------------------------------------------------------------------&lt;/p&gt;
&lt;p&gt;IncrTcl method that exposes the bug, part of Aejaks 'Table' class.&lt;br /&gt;
(The ::Label constructor '-from $c' wraps up an existing Java&lt;br /&gt;
object, rather than creating a new one.)&lt;/p&gt;
&lt;p&gt;----------------------------------------------------------------------------------&lt;/p&gt;
&lt;p&gt;public method setCellLabelAttrs {columnIdx rowNum args} {&lt;br /&gt;
if {[catch {&lt;br /&gt;
set c [::java::cast [::Label::_getObjType_] [$_obj_ -noconvert getCellComponent $columnIdx $rowNum]]&lt;br /&gt;
puts "getCellComponent return object $c"&lt;br /&gt;
puts "check for command defined: [info commands $c]"&lt;/p&gt;
&lt;p&gt;set label [::Label #auto -from $c]&lt;br /&gt;
} result]} {&lt;br /&gt;
error "invalid column or row, or cell component is not a Label: $result"&lt;br /&gt;
}&lt;br /&gt;
set result ""&lt;br /&gt;
set rc [catch {eval $label configure $args} result]&lt;br /&gt;
::itcl::delete object $label&lt;br /&gt;
if {$rc} {&lt;br /&gt;
error $result&lt;br /&gt;
} else {&lt;br /&gt;
return $result&lt;br /&gt;
}&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;----------------------------------------------------------------------------------&lt;/p&gt;
&lt;p&gt;Test case, first time works; second time through, the java object command is&lt;br /&gt;
missing.  This example creates a table with one row and two columns.&lt;br /&gt;
Invoking the 'setCellLabelAttrs' method changes the foreground color and text&lt;br /&gt;
of the Label in the first column. The first invocation works (setting the&lt;br /&gt;
text as 'RED' and changes its color to red.)  The second invocation fails,&lt;br /&gt;
as the java object command no longer exists.  The error raised is a result&lt;br /&gt;
of the 'from $c' missing the java object command.&lt;br /&gt;
----------------------------------------------------------------------------------&lt;br /&gt;
% Table .t -columns 2&lt;br /&gt;
% Pack .t&lt;br /&gt;
% .t insertRow 0 {first second}&lt;br /&gt;
% .t setCellLabelAttrs 0 0 -foreground red -text RED&lt;br /&gt;
%&lt;br /&gt;
getCellComponent return object java0x66&lt;br /&gt;
check for command defined: java0x66&lt;/p&gt;
&lt;p&gt;% .t setCellLabelAttrs 0 0 -foreground blue -text BLUE&lt;br /&gt;
%&lt;br /&gt;
getCellComponent return object java0x66&lt;br /&gt;
check for command defined:&lt;br /&gt;
invalid column or row, or cell component is not a Label: unknown option "-from"&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tom Poindexter</dc:creator><pubDate>Mon, 25 Aug 2008 04:53:10 -0000</pubDate><guid>https://sourceforge.netd2ac6f7f2d4e70506889e90efabf5624eacf40f6</guid></item></channel></rss>