JScript Type Mismatch looks like strange compiler error.

  • Thread starter Thread starter Heinz Kiosk
  • Start date Start date
H

Heinz Kiosk

I am adding JScript scripting to a C# ADO.NET application that uses
System.Data

I have derived a new class called BusinessTable from DataTable

The following sample script generates a type mismatch error when it is
compiled:
///////////////////////////
import System.Data;
import MyLib.MyObjects;

static function SomeFunction( p_Table : BusinessTable )
{
var descColumn : DataColumn = p_Table.Columns("SomeColumnName");
}
//////////////////////

However the following script works perfectly. The only difference is
wrapping the returned result in an object. The problem is as if the compiler
thinks that the Columns accessor returns something incompatible with a
DataColumn but if I can trick it then everything works perfectly at
runtime.
///////////////////////
import System.Data;
import MyLib.MyObjects;

static function SomeFunction( p_Table : BusinessTable )
{
var someColumn : DataColumn = Object(p_Table.Columns("SomeColumnName"));
}
////////////////////////

Many attempts to use either base methods or members of the BusinessTable
class seems to result in a type-mismatch from the compiler.

If I Messagebox.Show p_Table("SomeColumName").GetType().ToString() then it
correctly shows System.Data.DataColumn. So there is an example of a call
that both doesn't claim a type mismatch and shows the correct type being
returned.

What is going on? How can I fix my Invoke/CreateItem calls on the scripting
engine to stop it so that I can write scripting code without lots of silly
Object wrappers on my calls?

Thank you for your assistance.

Tom
 
I also have an error with type checking on arguments as well as returns.

eg I have a C# function

public class MyClass : DataColumn
{
public void SomeFunction(DataRow p_Row)
{....}
}

When I try to write a jscript call to SomeFunction with a DataRow as an
argument it won't compile, with a type mismatch error again. If I re-write
the above C# function as follows then everything works perfectly:

public class MyClass : DataColumn
{
public void SomeFunction(object pp_Row)
{
// Cast pp_Row because jscript cannot call with a DataRow as an
argument on my system
DataRow p_Row = pp_Row as DataRow;
....
}
}

As far as I can make out on my system jscript type-checking during
compilation is completely shot if the code refers to my classes rather than
the .NET framework classes.... But again if I can trick the system into
passing the syntax checks then everything works fine. Once again I have a
workaround but it is creating code that is even uglier than what I normally
write.....

Please Help.

Tom
 
Back
Top