Gracias por los aportes.
Si se le pasa un IBAN para comprobar sus dígitos de control la función fallaría (incluso la de C++), hay que revisar el paso 2 cuando ya es un IBAN.
Aquí les propongo mis modificaciones:
Código Delphi
[-]function GenerarIBAN(Pais, Cuenta: string): string;
function EsAlfanumerico(Caracter: Char): boolean;
begin
Result := CharInSet(Caracter, ['A'..'Z', 'a'..'z']);
end;
function EsNumerico(Caracter: Char): boolean;
begin
Result := CharInSet(Caracter, ['0'..'9']);
end;
var
cAux,
AuxCuenta: string;
i: Integer;
auxTemp: Extended;
begin
Result := '';
Cuenta := Trim(Cuenta);
if (Cuenta = '') or (Length(Cuenta) > 34) then
Exit
else
begin
Cuenta := UpperCase(Cuenta);
cAux := '';
for i := 1 to Length(Cuenta) do
if (EsAlfanumerico(Cuenta[i]) or EsNumerico(Cuenta[i])) then
cAux := cAux + AnsiString(Cuenta[i]);
Cuenta := cAux;
AuxCuenta := Cuenta;
if (EsAlfanumerico(Cuenta[1]) and EsAlfanumerico(Cuenta[2])) then begin
if (EsAlfanumerico(Cuenta[3]) or EsAlfanumerico(Cuenta[4])) then
Exit;
Pais := Copy(Cuenta, 1, 2); Cuenta := Copy(Cuenta, 5, Length(Cuenta)); AuxCuenta := Cuenta;
end
else
begin
if (Trim(Pais) = '') then
Pais := 'ES';
end;
Cuenta := Cuenta + Pais + '00';
cAux := '';
for i := 1 to Length(Cuenta) do
begin
if (EsAlfanumerico(Cuenta[i])) then
cAux := cAux + FormatFloat('00', Ord(Cuenta[i]) - 55) else
cAux := cAux + Copy(Cuenta, i, 1);
end;
Cuenta := cAux;
auxTemp := StrToInt(Copy(Cuenta, 1, 9)) mod 97;
cAux := FormatFloat('0', auxTemp); Cuenta := Copy(Cuenta, 10, Length(Cuenta)); while (Trim(Cuenta) <> '') do
begin
if (StrToInt(cAux) < 10) then
begin
cAux := cAux + Copy(Cuenta, 1, 8); Cuenta := Copy(Cuenta, 9, Length(Cuenta)); end
else
begin
cAux := cAux + Copy(Cuenta, 1, 7); Cuenta := Copy(Cuenta, 8, Length(Cuenta)); end;
auxTemp := StrToInt(cAux) mod 97;
cAux := FormatFloat('0', auxTemp);
end;
Result := Pais + FormatFloat('00', 98 - StrToInt(cAux)) + AuxCuenta;
end;
end;