Forum Discussion

msalvador's avatar
msalvador
Frequent Contributor
5 years ago
Solved

getActiveXObject couldn't close file

Hi guys,

I'm using getActiveXObject to parse an xml file.

This instruction is in a function, when I call this function twice, I have an error, I suppose because file is already open.

So there is a method like 'close',  I need to close and reopen this file n-times.

Here is the function.

 

 

function Translate_Msg_Static(MessageKey) // Translate a dinamic message
{
var Doc, s, ChildNode, Path;


Doc = getActiveXObject("Msxml2.DOMDocument.6.0");

Doc.async = false;

// Load data from a file
// We use the file created earlier
Doc.setProperty("ProhibitDTD", false);
Doc.load(Get_Translate_Mgs_Static_File());


// Report an error, if, for instance, the markup or file structure is invalid
if(Doc.parseError.errorCode != 0)
{
s = "Reason:\t" + Doc.parseError.reason + "\n" +
"Line:\t" + aqConvert.VarToStr(Doc.parseError.line) + "\n" +
"Pos:\t" + aqConvert.VarToStr(Doc.parseError.linePos) + "\n" +
"Source:\t" + Doc.parseError.srcText;
// Post an error to the log and exit
Log.Error("Cannot parse the document.", s);
return;
}
// Catch dinamically the path to search
Path = "//translation[@id='" + MessageKey + "']";
// Search single node
ChildNode = Doc.selectSingleNode(Path);

// If node exists then translate message else return messagekey
if (ChildNode != null)
return ChildNode.text;
else
return MessageKey
}

 

thanks in advantage

  • I got it, I found the bug.

    Original:

    function Get_Translate_Mgs_Static_File() // Get static file
    {
    if (Const_lib.Language== "it")
    return Get_Translate_Mgs_Static_File = "c:\\DL Console\\messages.it.xtb"
    else if (Const_lib.Language== "en_US")
    return Get_Translate_Mgs_Static_File = "c:\\DL Console\\messages.xtb"
    
    }
    


    Now work

     

    function Get_Translate_Mgs_Static_File() // Get static file
    {
    if (Const_lib.Language== "it")
    return  "c:\\DL Console\\messages.it.xtb"
    else if (Const_lib.Language== "en_US")
    return  "c:\\DL Console\\messages.xtb"
    
    }

    Tanks

     

     

     

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I suspect that the problem is not in the function you posted but in another function.  The DOMDocument object does not actually open a file per se.  The "load" function loads it into memory and closes the file...the XML file is no longer open at that point (if my memory serves).

     

    I suspect that your problem is in Get_Translate_Mgs_Static_File as that seems to be another custom function that is grabbing the actual file. If that is putting the file in use, that would be where the error could happen.

     

    When you step through the code in the debugger, where does the error happen?  That would be my first step in figuring out whether or not my suspicions are correct.

    • msalvador's avatar
      msalvador
      Frequent Contributor

      Thi is the error:

      TypeError: Get_Translate_Mgs_Static_File is not a function 17:15:40 Normal 9.93

      • msalvador's avatar
        msalvador
        Frequent Contributor

        I got it, I found the bug.

        Original:

        function Get_Translate_Mgs_Static_File() // Get static file
        {
        if (Const_lib.Language== "it")
        return Get_Translate_Mgs_Static_File = "c:\\DL Console\\messages.it.xtb"
        else if (Const_lib.Language== "en_US")
        return Get_Translate_Mgs_Static_File = "c:\\DL Console\\messages.xtb"
        
        }
        


        Now work

         

        function Get_Translate_Mgs_Static_File() // Get static file
        {
        if (Const_lib.Language== "it")
        return  "c:\\DL Console\\messages.it.xtb"
        else if (Const_lib.Language== "en_US")
        return  "c:\\DL Console\\messages.xtb"
        
        }

        Tanks