all groups > dotnet jscript > march 2004 >
You're in the

dotnet jscript

group:

eval problem


eval problem RP
3/3/2004 7:36:09 PM
dotnet jscript:
Hi all, I am having a problem updating class-level variables in eval
statements. Take a look at the code:-

class JavaService
{
var a: int = 0;

function Evaluate(evalString : String)
{
return eval(evalString);
}
}

When I call Evaluate("a = 10;"). It does not change a.

Any ideas?

TIA,
Param

Re: eval problem RP
3/3/2004 7:49:47 PM
In my scenario instead of an actual int, i have a custom object called
MyObject. And I try setting one of the properties in the eval. e.g.
Evaluate("a.id = 2;"). when I check id, it is not 2.


[quoted text, click to view]

Re: eval problem Chris R. Timmons
3/3/2004 8:12:40 PM
"RP" <rp@nospam.com> wrote in
news:eoduyKYAEHA.1468@tk2msftngp13.phx.gbl:

[quoted text, click to view]

Param,

This works for me (.Net 1.1):

// Example.js
import System;

var js = new JavaService();
js.Evaluate("mo.a = 10");
js.PrintA(); // Will print 10.

public class JavaService
{
public var mo : MyObject = new MyObject(); // Can't be private.

public function Evaluate(evalString : String)
{
return eval(evalString);
}

public function PrintA()
{
Console.WriteLine(mo.a);
}
}

public class MyObject
{
public var a : int = 0; // Can't be private.
}


Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
Re: eval problem RP
3/3/2004 11:30:45 PM
Chris, couple of things:

1. I am running .net 1.0 sp2.
2. The dll file that holds MyObject is written in vb and is in a seperate
dll.
3. I am invoking my JavaService from vb code, setting the MyObject (public)
for initial values.
4. Now try changing one of the properties in Eval. I can read the properties
fine. The change wont take effect!

thanks,
RP

P.S. Upgrading to .net 1.1 is not an option at this time since tons of code
may break or would need to be re-compiled.

[quoted text, click to view]

Re: eval problem RP
3/3/2004 11:42:41 PM
I also did some testing. My class declaration has nested classes. I am able
to access top level properties. The moment I get into the first nested
class's properties - no luck!.

[quoted text, click to view]

Re: eval problem RP
3/3/2004 11:45:56 PM
Sorry, the main class has nested Structures defined rather than classes.
Could that be the problem?

[quoted text, click to view]

Re: eval problem RP
3/4/2004 9:32:30 AM
Just as an FYI to everyone, I dont know if it is a bug in .net 1.0, but the
Structures were the problem. I was up late last night and moved everything
over to Classes and voila! Seems to be working fine now..... Is this a known
issue? Someone from MS please contact me for more details.

thanks,
Param

[quoted text, click to view]

AddThis Social Bookmark Button