Alain Pastor wrote: > I would try to store the DIAGNOSIS$ array in a global handle if it > is not a too heavy change and see what happens. If somewhere in your > code you are overriding memory, you will have probably to deal with > another issue perhaps more severe. > > Finally, I would change the FN repElement call with a function that > I have recently adapted from an example by Apple which I believe is > doing quite the same thing (caution repElement has been used by > hundred of programmers as opposed to the following one that I have > never tested in real conditions nor released): > > /* > Usage: > err% = FN SetIndString(theString$,ResID%,stringIndex%) > > This function sets the stringIndex-th string in the STR# > resource specified > by ResID% and returns an error code (_resNotFound) if the > operation fails. > */ > CLEAR LOCAL MODE > '~'8 > LOCAL FN SetIndString( @inStrP AS PTR, resID AS SHORT, item AS SHORT ) > '~'9 > DIM AS UNSIGNED LONG offset'resource offset to str to replace > DIM AS HANDLE resH'handle pointing to STR# resource > DIM AS PTR strP'string pointer to STR# string to replace > DIM AS LONG oldSize,newSize'size of STR# resource before and > after call > DIM AS SHORT i, err'counter to index up to strIndex > > err = _resNotFound > IF resID < 1 THEN EXIT FN > resH = FN Get1Resource(_"STR#",resID) > IF FN ResError != _noErr OR resH = _nil THEN EXIT FN'make sure > resource exists > IF item < 1 OR item > resH..nil% THEN EXIT FN'make sure index is > in bounds > > HLock(resH) > HNoPurge(resH) > offset = SIZEOF(SHORT) > strP = [resH] + SIZEOF(SHORT)'get a pointer to the string to replace > FOR i = 1 TO item - 1 > offset += 1 + strP.nil` > strP += 1 + strP.nil` > NEXT Alain, if the new string is smaller than the old string and you shrink the handle here, won't you be reading data from outside the handle when you do the blockmove later? > oldSize = FN GetHandleSize(resH)'grow/shrink resource handle to > make room for new string > newSize = oldSize - strP.nil` + inStrP.nil` > HUnlock(resH) > SetHandleSize(resH,newSize) > LONG IF FN MemError > ReleaseResource(resH) > EXIT FN > END IF > HLock(resH) > strP = [resH] + offset > /* move old data forward/backward to make room */ Reads data from outside the handle if handle was reduced in size?? > BlockMove(strP + strP.nil` + 1, strP + inStrP.nil` + 1, oldSize - > offset - strP.nil` - 1) > BlockMove(inStrP,strP,inStrP.nil` + 1)'move new data in > ChangedResource(resH)'write resource out > WriteResource(resH) > HPurge(resH) > ReleaseResource(resH) > err = FN ResError > END FN = err > -- Seems like if the new string is larger than the one being replaced, you expand the handle first then do the blockmoves. On the other hand if it is smaller than the one being replaced, you do the blockmoves first, then shrink the handle. Or am I missing something? Regards, Charles P.