The article you read must have been based on TclBlend 1.0. There
were some changes made in the 1.1 release in the tcl.lang.ReflectObject
class. The point of the changes were to add support for "typed objects".
If you want to read up on the reasons for these changes you can check
out the paper I wrote for the last Tcl conference here
http://www.cs.umn.edu/~dejong/tcl/paper.html (see section 5).
> I was trying to compile the example in the Dr. Dobbs article about TclBlend:
>
> import java.awt.event.*;
>
> public class TestActionListener implements ActionListener {
> public TestActionListener(tcl.lang.Interp i, String s) {
> interp = i;
> script = s;
> }
>
> public void actionPerformed(ActionEvent e) {
> try {
> interp.setVar("event",
> tcl.lang.ReflectObject.newInstance(interp, e), 0);
> interp.eval(script);
> } catch (tcl.lang.TclException te) {
> System.out.println("error in ActionListener script: "
> + interp.getResult());
> }
> }
>
> private tcl.lang.Interp interp;
> private String script;
> }
>
> ( http://www.ddj.com/articles/1998/9802/9802d/9802d.htm#l5 )
>
> I get the following compiler error:
>
> TestActionListener.java:12: Wrong number of arguments in method.
> tcl.lang.ReflectObject.newInstance(interp, e), 0);
> ^
> 1 error
The signature is newInstance(Interp, Class, Object). The Object argument
is simply the Java object that should be reflected and the Class
argument is the type that the Object argument should be reflected as.
For instance if the Object argument is an instance of the java.lang.String
class, it could be reflected (stored in the interp's ReflectObject table)
as a java.lang.String or a java.lang.Object. In your example you would
want tocall newInstance like this.
tcl.lang.ReflectObject.newInstance(interp, ActionEvent.class, e)
What you do not want to do is call e.getClass(). The docs for the
ReflectObject class (included in the Tcl Blend dist) have a
more detailed example of why calling Object.getClass() is really
bad.
I hope that helps
Mo DeJong
> Using java::info in Tcl I determined that the signature of newInstance is:
>
> {tcl.lang.TclObject {newInstance tcl.lang.Interp java.lang.Class
> java.lang.Object} tcl.lang.TclException}
>
> So what should the class argument be?
>
> --------------------------------------------------------------------------
> Hugh Dunne, CIENA Core Switching Division
> 10201 Bubb Rd., Cupertino, CA 95014
> [EMAIL PROTECTED] +1-408-865-6485
>
> ----------------------------------------------------------------
----------------------------------------------------------------
The TclJava mailing list is sponsored by WebNet Technologies.
To subscribe: send mail to [EMAIL PROTECTED]
with the word SUBSCRIBE as the subject.
To unsubscribe: send mail to [EMAIL PROTECTED]
with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'.
A list archive is at: http://www.findmail.com/listsaver/tcldallas/