Thanks Fred/RVK - my mind is still stuck in the realms of Turbo Pascal
so I haven't fully investigated SysUtils and this project was going to be a 'ten minute' job about 3 hours ago!!
Yes 'Buffer' is a string - rather than a short string - I haven't done much string handling where the length is greater than 255 and this was one of the reasons for the project.
I have found a reason for the error - and as RVK suggests it is something else in the code. There are a number of search and replace routines and one of them involved a semicolon which I mistakenly thought would always be present after an ampersand and when it wasn't, the further processing made the buffer length 'infinite' --- well certainly greater than 'word' --- which totally confused the 'pos' function by 'wrapping' the pos when > 65535!
Now StringReplace and ReplaceStr have been brought to my attention I'll look at them - - - though WPs suggestion (thanks) might be better - - - I'll see which is the quickest.