Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: mgourde on January 23, 2021, 08:28:23 am

Title: ActiveX vs COMObject and Javascript
Post by: mgourde on January 23, 2021, 08:28:23 am
There was a recommandation by Sparx to move from JScript to Javascript for matter of futur support. Good, it is almost compatible :)

The problem is that the Javascript implementation does not support the Microsoft extension 'activeXObject' and to fix that you must change it to 'COMObject'. It will work  for the following object:  'MSScriptControl.ScriptControl' ,'MSComDlg.CommonDialog', 'Scripting.FileSystemObject,  with no extensive testing, but it does the basic job.

It will not work for instanciating XML 'MSXML2.DOMDocument' or 'Excel.Application'. XML is a requirement in order to parse the result from SQLQueries (repository). The symptoms are mostly a sudden disapperance of the a receiving variable or a silent failure of the execution of a function or method of the COMObject.

I have tried many variation such as referring different versions of a COMObject, different spelling, changing the character cases,  etc ..

I looked through the forum without success. Subjects with similar problems were mentionned but no solution. This is not in favor of moving to Javascript.

Any idea? Should this be reported to Sparx support?

Regards

Martial
Title: Re: ActiveX vs COMObject and Javascript
Post by: qwerty on January 23, 2021, 08:33:30 am
Likely a case for a bug report (link down  this page in the Support section).

I'm using Python for scripting. Different issues there but I can do any API stuff from EA. Not helpful for you, I know...

q.
Title: Re: ActiveX vs COMObject and Javascript
Post by: Geert Bellekens on January 23, 2021, 06:58:01 pm
Hi Martial,

Yes, try sparx support and see what they say.

I do all of my scripting in VBScript, so I haven't encountered any of these issues.

Geert

PS. I hope they never stop supporting VBScript, because that would mean years of code to be rewritten :-\
Title: Re: ActiveX vs COMObject and Javascript
Post by: jharvey6 on August 04, 2022, 05:57:31 am
How do you feel about VBscript being deprecated in further releases?
Title: Re: ActiveX vs COMObject and Javascript
Post by: Paolo F Cantoni on August 04, 2022, 08:14:14 am
Hi Martial,

Yes, try Sparx support and see what they say.

I do all of my scripting in VBScript, so I haven't encountered any of these issues.

Geert

PS. I hope they never stop supporting VBScript because that would mean years of code to be rewritten. :-\ 
Not wrong!

I use VBScript extensively (though not exclusively) because it has ByRef parameter passing.  I couldn't see how to do that in JScript.  Is it possible?

Paolo
Title: Re: ActiveX vs COMObject and Javascript
Post by: Eve on August 04, 2022, 08:45:12 am
PS. I hope they never stop supporting VBScript, because that would mean years of code to be rewritten :-\
Unlikely to happen. What has happened is that the Microsoft components that EA relies on to debug VBScript and JScript are effectively dead. By contrast, the Javascript support is fully contained within our codebase, so that's recommended.

I use VBScript extensively (though not exclusively) because it has ByRef parameter passing.  I couldn't see how to do that in JScript.  Is it possible?
Yes it is. All variables and arguments are assigned by value, but for objects the value of the variable is a reference. So to pass something by reference all you need to do is wrap it in an object and pass that.
Title: Re: ActiveX vs COMObject and Javascript
Post by: Paolo F Cantoni on August 04, 2022, 10:49:52 am
PS. I hope they never stop supporting VBScript because that would mean years of code to be rewritten :-\
Unlikely to happen. What has happened is that the Microsoft components that EA relies on to debug VBScript and JScript are effectively dead. By contrast, the Javascript support is fully contained within our codebase, so that's recommended.

I use VBScript extensively (though not exclusively) because it has ByRef parameter passing.  I couldn't see how to do that in JScript.  Is it possible?
Yes, it is. All variables and arguments are assigned by value, but for objects, the value of the variable is a reference. So to pass something by reference, all you need to do is wrap it in an object and pass that.
(my emphasis)
I already knew that, but that was a shirtload of work to just get a string passed ByRef.  If I were a masochist, I could do the same in VBScript, so your comment is correct but useless.
Nevertheless, based on your point about the Microsoft components, we'll have to start planning the changeover.

Paolo
Title: Re: ActiveX vs COMObject and Javascript
Post by: Farkas on September 26, 2023, 01:24:14 am
Hi!

Maybe everyone found this answer already, maybe not, but now in 2023 the following works with javascript:
Code: [Select]
var xmlDOM = new COMObject("MSXML2.DOMDocument.6.0");
Actually, there's a function in Local Scripts.JavaScript - Model Search (Operations) Example that tries a lot of the possibilities in order to find one working:
Code: [Select]
function CreateXMLObject()
{
var xmlDOM = null;
var ProgId = "";
var attempt = 0;

while (xmlDOM == null)
{
switch (attempt++)
{
case 0: ProgId = "MSXML2.DOMDocument.6.0"; break; //MSXML 6.0
case 1: ProgId = "MSXML2.DOMDocument.3.0"; break; //MSXML 3.0
case 2: ProgId = "MSXML2.DOMDocument"; break; //MSXML 3.0
case 3: ProgId = "MSXML2.DOMDocument.4.0"; break; //MSXML 4.0
default: return;
}
try { xmlDOM = new COMObject( ProgId ); } catch (err) { xmlDOM = null; }
}

if (xmlDOM != null)
{
xmlDOM.validateOnParse = false;
xmlDOM.async = false;
}

return xmlDOM;
}

(I tested this in EA 16.1 and 15.2)

Farkas