Author Topic: ActiveX vs COMObject and Javascript  (Read 2471 times)

mgourde

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
ActiveX vs COMObject and Javascript
« 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

qwerty

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +387/-299
  • I'm no guru at all
    • View Profile
Re: ActiveX vs COMObject and Javascript
« Reply #1 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.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 12670
  • Karma: +525/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: ActiveX vs COMObject and Javascript
« Reply #2 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 :-\

jharvey6

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: ActiveX vs COMObject and Javascript
« Reply #3 on: August 04, 2022, 05:57:31 am »
How do you feel about VBscript being deprecated in further releases?

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8484
  • Karma: +246/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: ActiveX vs COMObject and Javascript
« Reply #4 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
« Last Edit: August 04, 2022, 08:17:38 am by Paolo F Cantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7913
  • Karma: +109/-20
    • View Profile
Re: ActiveX vs COMObject and Javascript
« Reply #5 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.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8484
  • Karma: +246/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: ActiveX vs COMObject and Javascript
« Reply #6 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
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Farkas

  • EA Novice
  • *
  • Posts: 14
  • Karma: +1/-0
    • View Profile
Re: ActiveX vs COMObject and Javascript
« Reply #7 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