#16 WordPosL - Range check error

open
nobody
Strings (5)
5
2013-01-15
2003-05-26
Maxim Kammerer
No

StStrL.WordPosL raises "Range Check Error" if
parameter S = AWord.

To reproduce:

var
S : string;
W : string;
position : cardinal;
begin
S := 'hello';
w := 'hello';
WordPosL( s, ' ', w, 1, position );
end;

To fix:
function StStrL.WordPosL
...

begin // of procedure
if (S = '') or (AWord = '') or (pos(AWord, S) = 0) or
(N < 1) then begin
Result := False;
Position := 0;
Exit;
end;

// begin inserted code
if (S = AWord ) then begin
Result := True;
Position := 1;
exit;
end;
// end inserted code

....

Some of the other WordPos? may be also affected.
(I've not tested this)

Related bug #684836

Discussion