DocumentCache Object

It is very important to understand the DocumentCache object when using the Visual Tools Object Model. Although HomeSite and ColdFusion Studio enable you to open dozens of files at once, only the active document is kept in memory. When a document becomes inactive (that is, when the user switches to a different document in the document tab), the previously active document is cached in order to conserve resources.

Every open document has an element in the Application.DocumentCache array. To refer to a specific cached document, use Application.DocumentCache(Index), where Index is the index of the document in the document tab. The JavaScript example below shows how to loop through the array:

    var app = Application;
    for (idx = 0; idx < app.DocumentCount; idx++) {
      sFile = app.DocumentCache(idx).Filename;
    }


Here's the same code in VBScript:

    set app = Application
    for idx = 0 to app.DocumentCount - 1
      sFile = app.DocumentCache(idx).Filename
    next


If you know the filename of an open document, you can retrieve its index by using the Application.GetTabIndexForFile function, like this:

    var app = Application;
    idx = app.GetTabIndexForFile('c:\docs\file.htm');
    bReadOnly = app.DocumentCache(idx).ReadOnly;


In order to access more information about a cached document, you must first make it the active document and refer to it using the Application object's ActiveDocument property. To do this, set the Application.DocumentIndex property to the index of the cached document.


Properties
Note: All properties of the DocumentCache object are read-only.

Text (OleString)
Returns the text (file contents) of the cached document.

Modified (WordBool)
Returns True if the cached document has been modified since it was last saved.

Filename (OleString)
Returns the filename of the cached document.

ReadOnly (WordBool)
Returns True if the cached document is read-only.