For the Levenshtein algorithm I have found this implementation for Delphi.
I need a version which stops as soon as a maximum distance is hit, and return the distance found so far.
My first idea is to check the current result after every iteration:
for i := 1 to n do
for j := 1 to m do
begin
d[i, j] := Min(Min(d[i-1, j]+1, d[i,j-1]+1), d[i-1,j-1]+Integer(s[i] <> t[j]));
// check
Result := d[n, m];
if Result > max then
begin
Exit;
end;
end;