Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Kids maths
Wed, Mar 13 2013 1:05 PMPermanent Link

Matthew Jones

If MyVar contains 3, what is the result of this line?
MyVar := MyVar + 1;

That's right - 31.

Plainly my final code is interpreting it as a string. The value is coming through
the RemObjects interface, which appears to handle Integer differently to String. I
can't seem to influence this.

Hmm, okay, I've used Inc(MyVar); and it works fine, but if there is a way to make
this better, I'm all ears. Thanks.

(I am so glad I'm not actually writing the Javascript - what a horrible language!)

/Matthew Jones/
Wed, Mar 13 2013 4:25 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Plainly my final code is interpreting it as a string. The value is coming
through the RemObjects interface, which appears to handle Integer
differently to String. I can't seem to influence this. >>

This is one of the issues with JS - variables can be any type at any time.
Which makes it easier on the developer in some cases, but much harder on
anyone else that has to read the code.

<< Hmm, okay, I've used Inc(MyVar); and it works fine, but if there is a way
to make this better, I'm all ears. Thanks. >>

It sounds like you've got something declared as an Integer that is actually
a String in the external interface in EWB.  That's the first part of the
issue.  If you have a method/methods that can return various values, then
you need to define multiple methods in the external interface so that EWB
can properly type-check things.

The second part of the issue is that you've got JS code that is returning
something as a String when you expect it to be an Integer.  This may just be
an issue with your interface, as noted above, or something more problematic
in the sense that the JS code is returning multiple types via a method, etc.
and does not give you a defined way of discovering the type being returned.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Mar 14 2013 5:28 AMPermanent Link

Matthew Jones

> JS code that is returning
> something as a String when you expect it to be an Integer.

I can't see anything wrong with the interface code, but I guess it must indeed be
ending up as a string. It might be nice to have a way to "force" something to be a
number. I noticed in the IntToStr function that you do Number($0).AsString, which
presumably does that. I tried using Number() myself, but it wasn't known. But
something that would do that (I wonder if Inc(MyVar, 0) would work?) might be
handy.

That said, the compiler should know that it is a math operation and not a
concatenation, so could it start with Number() on the first item to make it work
the right way?

/Matthew Jones/
Thu, Mar 14 2013 12:49 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< I can't see anything wrong with the interface code, but I guess it must
indeed be ending up as a string. It might be nice to have a way to "force"
something to be a number. I noticed in the IntToStr function that you do
Number($0).AsString, which presumably does that. I tried using Number()
myself, but it wasn't known. But something that would do that (I wonder if
Inc(MyVar, 0) would work?) might be handy. >>

It isn't necessary for EWB because the compiler makes sure that there aren't
any type issues.  You need to figure out what is wrong with the external
interface and that will solve your problem.

<< That said, the compiler should know that it is a math operation and not a
concatenation, so could it start with Number() on the first item to make it
work the right way? >>

No, for the reason above.  I'm not going to litter the emitted JS code with
type-casting because incorrect types are being leaked in through an external
interface.

Tim Young
Elevate Software
www.elevatesoft.com
Image