Difference in CompareName method

  • We recently updated to latest version 9.2, and WPRTEDefs.TWPTextObj.CompareName evaluates differently. One example:

    Name = *spFromFields.fromName, aText = *spToFields.toName.

    Code:

    b := Copy(aText, 1, i - 1);

    a := Copy(aText, Length(aText) - i - 1 ,Length(aText) - i);

    aa := Copy(Name, Length(Name)-Length(a)+1, Length(a));

    Result:= ((i = 1) or (CompareText(b, Copy(Name, 1, i - 1)) = 0)) and (CompareText(aa,a) = 0);

    local variable b = ''

    local variable a = 'ame'

    local variable aa = 'ame'

    Result = True

    In the version we had been using, the evaluation wasn't broken into local variables, and Result was properly False.

    Is this a known issue that can be fixed, without us changing the source code?

    Thanks

    • Offizieller Beitrag

    Thank you for reporting this error. The old code was not working in some cases.

    But the new code is incorrect, it should be

    b := Copy(aText, 1, i - 1);

    a := Copy(aText, i+1 ,Length(aText) - i); // 23.6.2021

    if Length(Name)>=Length(a) then

    begin

    aa := Copy(Name, Length(Name)-Length(a)+1, Length(Name));

    Result:= ((i = 1) or (CompareText(b, Copy(Name, 1, i - 1)) = 0)) and (CompareText(aa,a) = 0);

    end

    else Result := false;