Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > JavaScript/ActiveX passing params by reference
User Name
Password
REGISTER NOW!




Reply
 
1 4th September 08:50
stéphane
External User
 
Posts: 1
Default JavaScript/ActiveX passing params by reference



Hi all,

I would like to pass a "variable" by reference between a javascript code and
my application.
I will try to explain what I want and what I tried as breifly as possible .

The object that I export from my application is a tagged area which was
previously used internally to return a bunch of results to users.
For instance if users wanted to create a butterworth filter of order five
the command result area was:

<Type> <Tag> <Value>
Int "ORDER" 5
double "AMCOEF1" 0.000254574
double "AMCOEF1" 0.023548700
double "AMCOEF1" 1.000254574
.....

Now what I want is "advanced users" to access this area from Javascript
codes. So I exported a COM object with the following interface (pseudo code
much more looking like CORBA idl)

interface TalkArea
{
void Restart(); // move to the first line of the area
void Reset(); // Erase the content of the area

bool GetInt(BSTR* pTag [out], int* pValue [out]); // Get a line in the
area assuming it is an integer and move to the next line in the area
......GetDlb, GetStr, and so on.

bool FindInt(BSTR Tag [in], int* pValue [out]); // Look in the whole
area for integer with the provided tag and return its value in pValue
};


1) The first problem and its solution
------------------------------------

// Javascript code
var TaggedArea = CreateObject("MyApp.ITalk");
var iOrder;
if (TaggedArea.FindInt("ORDER", iOrder))
{
// blabla.....
}

The problem here is that I cannot pass "iOrder" by reference. I found a
intermediate solution by changing my interface to:

interface TalkArea
{
int FindInt(BSTR Tag [in]); // If tag is not found I return MaxInt
};

(Ok it is all pseudo code, fortunatly the real code works really fine !)


2) The problem which I can't find any solution
----------------------------------------------

// Javascript code
var TaggedArea = CreateObject("MyApp.ITalk");
var AnInt;
var ATag;
TaggedArea.Restart();
if (TaggedArea.GetInt(AnInt, ATag))
{
// blabla.....
}

The probem here is that I still cannot pass by reference from Javascript
and, worst, I cannot use an intermediate solution to return two values at
the same time.

My only solution is to have GetInt to work with Javascript objects and then
modify them internally working with Variant but I don't know
how to do... I have searched the internet and forums, but I found no
example. I would greatly appreciate if you could provide me with a piece of
code for doing this (I use C++ builder for my application).

A cool and simple thing could be

// Javascript code
function IntObject(iValue)
{
this.value = iValue;
}
function StrObject(sValue)
{
this.value = sValue;
}
var TaggedArea = CreateObject("MyApp.ITalk");
var AnInt = new IntObject(0);
var ATag = new StrObject("");
TaggedArea.Restart();
if (TaggedArea.GetInt(AnInt, ATag)) // Now I can modify AnInt and ATag
because these are objects.........
{
// blabla
}

Thanks by advanced for the help you could provide me with in solving this
issue....

Stéphane.
  Reply With Quote


 


2 4th September 08:50
remy lebeau \(teamb\)
External User
 
Posts: 1
Default JavaScript/ActiveX passing params by reference



<snip>

When dealing with scripting languages, you need to use VARIANT for all of
your parameters.

However, Javascript always passes parameters by value, never by reference.
There is nothing you can do to pass values by reference in Javascript, so
you will have to change your design to only rely on parameters passed by
value and on return values.

How about wrapping the individual items it a second object that has
properties for returning the type, tag, and value individually? And then
the main tagged area can contain a collection of these objects, and the
script code simply loops through the collection as needed, or finds a
particular object in the collection. For example:

var TaggedArea = CreateObject("MyApp.ITalk");
var Tag = TaggedArea.Find("Int", "ORDER");
if( IsObject(Tag) )
{
var iOrder = Tag.Value;
//...
}

var TaggedArea = CreateObject("MyApp.ITalk");
var Enum = new Enumerator(TaggedArea.Tags);
Enum.moveFirst();
while( !Enum.atEnd() )
{
var Tag = Enum.item();
alert(Tag.Type + ", " + Tag.Tag + ", " + Tag.Value);
Enum.moveNext();
}


Gambit
  Reply With Quote


 


3 4th September 08:50
michael harris
External User
 
Posts: 1
Default JavaScript/ActiveX passing params by reference


have you considered this approach
IHTMLScriptElement
IHTMLParamElement

http://msdn.microsoft.com

Web Development / programming and reusing the browser / MSHTML reference /
Interfaces and Scripting Objects
  Reply With Quote
4 4th September 08:50
remy lebeau \(teamb\)
External User
 
Posts: 1
Default JavaScript/ActiveX passing params by reference


Those have nothing to do with this topic. Those are for retrieving some
information about <script> and <param> tags from the DOM (Document Object
Model) of a web browser control. They are not for passing parameters to an
ActiveX control or retreiving the parameters back.


Gambit
  Reply With Quote
5 4th September 08:50
stéphane
External User
 
Posts: 1
Default JavaScript/ActiveX passing params by reference


Thanks a lot, It sounds great,
I was too single minded with willing to have parameters passed by reference.

Stéphane

----- Original Message -----
From: "Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com>
  Reply With Quote
6 4th September 08:50
michael harris
External User
 
Posts: 1
Default JavaScript/ActiveX passing params by reference


hmm, my mistake, I assumed methods such as
// Javascript code
var TaggedArea = CreateObject("MyApp.ITalk");
var iOrder;
if (TaggedArea.FindInt("ORDER", iOrder))
{
// blabla.....
}

Might wind up in a DOM (Document Object Model) A web browser control.
as part of the d / html.

must have benn the java thing or comments such as
{ I export from my application is a tagged } made me think it might be a web
or browser based application.

If my version of IE loads a page with some script in it, well, now you know
why I mentioned it.

If you want to load the jave or call it from c++ (That may have nothing to
do with this topic), I will need to look around for some code I use. (I
know, i keep hearing you can't do that, but mine works fine)..

excuse me again.

--
Michael

"Remy Lebeau (TeamB)"
  Reply With Quote
7 8th September 08:24
remy lebeau \(teamb\)
External User
 
Posts: 1
Default JavaScript/ActiveX passing params by reference


<snip>

Not, the actual scripting and actual ActiveX control are not part of the
DOM. Only the containing HTML elements. Even if they were part of the DOM,
that wouldn't help anyway, since the original question had to do with actual
scripting accessing an actual ActiveX control.

Also, the scripting may not even be in a web browser to begin with. It
could be in the Windows Scripting Host, for example, which doesn't use a
browser at all.


Gambit
  Reply With Quote
8 8th September 08:24
michael harris
External User
 
Posts: 1
Default JavaScript/ActiveX passing params by reference


Yes , But it may be that an ActiveX dll was the only solution considered.
(embedding into the script. )
Stéphane may not have been aware that under certain condition, there are
alternatives. (take the activex. out of the loop).


<duh>


<again, this could be interpreted as,' how can i communicate with my
script'>

< then again, maybe it is>


--<michael>
  Reply With Quote
9 8th September 08:24
stéphane
External User
 
Posts: 1
Default JavaScript/ActiveX passing params by reference


Hi,

My application has nothing to do with "web programming", is it a
"scientific" one.
The reason I uses Javascript with it is only to replace an old macro
language
which is good at running command with "hard coded" parameters but awfull
when trying to
generate parameters on the fly. Now it is easy :

// Javascript sample
var Parser = CreateObject("MyApp.IShell");
var dParam1 = Math.Cos(3.0*2.35699*Math.Pi);
var dParam2 = Math.Sin(3.0 + dParam1)/Math.Log(balblalblal......);
Parser.Run("Rescale " + dParam1 + " " dParam2);

before it was:

// Macro sample
Double dParam1
Double dParam2
// About 10 lines with horrible syntax to calculate values (and no
debugging tool at all !)
Rescale %ddParam1 %ddParam2

(Yet another cool thing is that Javascript let me run about 1000 commands
per second when my macro language is only running 20/seconde)


The reason for now willing to export the internal TaggedArea is to generate
some application code on the fly.
Users will only write the "active" part. I'll take care of wrapping it with
all to the hidden stuff of
taggedArea and other internal considerations. All of this will be pushed in
the windows script host
to be executed later on on demand.

Now users will develop and tests their own set of algorithms instead of
calling me each and every day to change and recompile the
definitive C++ code. And if results are not the expected one, that's no more
my problem wondering if it is an algorithmic or coding
issue. [Arrrghh, no more work stopped by boring hot line support with users
who never know what they really want, sounds wonderfull ;o) ]


"Michael Harris" <techonos-NO-SPAM-@attbi.com> a écrit dans le message de
news:402c110e@newsgroups.borland.com...
  Reply With Quote
10 8th September 08:24
remy lebeau \(teamb\)
External User
 
Posts: 1
Default JavaScript/ActiveX passing params by reference


You could embed Microsoft's scripting engine into your application directly,
using the IActiveScript and IActiveScriptParse interfaces. Then you don't
need WSH at all. My company just started incorporating this stuff ourselves
and it has worked out very nicely.


Gambit
  Reply With Quote
Reply






Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666