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.
|