Problem: 1615789

Title: (Documents - Editions) TEditionDocument::DoRead does not set ResFile

Received: Dec 29 1996 11:39AM


There is a bug in MacApp 3.3.1 UEditionDocument.cp

TEditionDocument::DoRead. The Problem is that this method does *not* make sure, that the document is the current resource-file. It is possible, that sections are read from the wrong document, if multiple documents are open at the same time and they all contain subscribers.

Below you will find a modified version of TEditionDocument::DoRead which saves, sets and restores the resfile, so the section-resource is read from the right document.

void TEditionDocument::DoRead(TFile* aFile, Boolean forPrinting)        //
override 
{
        MAVolatileInit (short, curResFile, MACurResFile ());
        
        Inherited::DoRead(aFile, forPrinting);
        
        FailInfo fi;
        Try(fi)
        {
                // !!! BUG-FIX !!! Inserted a FailureHandler
                // Save, set, and restore the current ResFile
                
                if (aFile)
                        aFile->UseResource ();
                // 1. read in (from a resource) fStopAllEditions and fShowSectionBorders 
                this->DoReadSettings(aFile);
                // 2. create the section objects and tell each section to read itself in 
                for (short i = 1; i <= Count1Resources(rSectionType); ++i)
                {
                        short theID;
                        Handle h;
                        h = Get1IndResource(rSectionType, i);   // get the resource handle 
                        FailNILResource((Handle)h);
                        theID = (short)(*((SectionHandle)h))->sectionID;
                        switch ((*((SectionHandle)h))->kind)
                        {
                                case stPublisher:
                                        this->DoReadPublisher(aFile, theID);
                                        break;
                                case stSubscriber:
                                        this->DoReadSubscriber(aFile, theID);
                                        break;
                                default:
        #if qDebug
                                        ProgramBreak("SectionHandle appears to be corrupt");
        #endif
                                        break;
                        }
                }
                MAUseResFile (curResFile);
                fi.Success ();
        }
        else
        {
                MAUseResFile (curResFile);
                fi.ReSignal ();
        }
} // TEditionDocument::DoRead 

Fix:

I was unable to reproduce this using two Calc documents and two different published/subscribed editions for those documents. I can imagine the developer may have reproduced the problem if running into an error reading a subscriber throwing failure or if changing the CurResFile some time after opening the resource fork of the file. I suggest we keep the fix in order to have a safe save/restore and defer verification to the developer who reported it.


Fixed by using CTempUseResFile_AC.