Fonction qui remplace les caractères entrés par des étoiles (*)
Bonjour,
Voilà une fonction qui remplace les caractères entrés par (*) comme on trouve dans les logiciels qui demandent le code de sécurité ou les appareils du téléphone :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| function askpassword (passwordchar : char; minlength, maxlength : Longint) : String;
var
C : Char;
S : String;
begin
S := '';
Repeat
C := Readkey;
If ((C <> chr(13)) and (C <> chr(8)) and (length(S) <> maxlength)) then Write(passwordchar);
If ((C <> chr(13)) and (C <> chr(8))and (length(S) <> maxlength)) then S := S + C;
If length(S) = maxlength then write(chr(7));
If C = chr(8) then S := '';
If ((C = chr(13)) and (length(S) < minlength)) then Write(chr(7));
Until ((C = chr(13)) and (length(S) > minlength - 1));
askpassword := S;
end; |
Appelez la fonction comme ça :
Code:
1 2 3 4 5
| var
password : String;
begin
password := askpassword( '*', 0,-1);
end. |