State of the Nation

Another painful point I have just noticed. Again, this was embedded in the SDK, but so deep you would hardly notice it until you looked for it specifically:

All instances of Winword will use the same instance of your ISmartDocument object

This following paragraph from the SDK (here) shows that:

If you have multiple documents open, and more than one of those documents uses the same XML expansion pack, your global variables are tied to the ISmartDocument interface, of which there is only one instance for the XML expansion pack, not for each individual instance of a smart document.

What it basically means is that ANY variable declared in your Smart Document object is, in effect, a static variable - that's because the ISmartDocument object is instantiated as a singleton and simply called whenever it is needed.

This means that you can NOT save any state information that you wouldn't want shared between instances of Word, assuming you have several documents open at the same time linked to the smart document solution.

The suggested solution to keep instance-specific state is to have a Hashtable with the Document as the key. A bit excessive, I think, but I guess it's as good a way as any. Just remember that you shouldn't save the Current Document as a local variable, but extract it on every method call from the Target parameter passed to the PopulateX methods - it's a Word Range object, and has the Document as a parameter.

 

1 Comment

  • Robin said

    Hello,

    I have got a problem like this only.
    I have made a smartTag dll and i register that dll to my system.
    Now when i open any Excel sheet it gets attached to it.

    My Query is how can i restrict so that only a particular Excel sheet say exmple1.xls sheet ,reflect the given smarttag.Example2.xls shouldnot refelct the smartTag.

    Any suggestion.

    Robin

Comments have been disabled for this content.