Замените такой код: if Str[I] in LeadBytes then
использованием функции IsLeadChar: if IsLeadChar(Str[I]) then