procedure TForm1.Button1Click(Sender: TObject); const Letters = 'XMRUONEGLA'; Numbers = '0123456789'; var ShortStr: ShortString; i, j: Integer; P: Byte; begin j := 0; Label1.Caption := ''; ShortStr := Edit1.Text; if Length(ShortStr) > 9 then Exit; for i := 1 to Length(ShortStr) do begin P := Pos(ShortStr[i], Letters); if P > 0 then Label1.Caption := Label1.Caption + Numbers[P]; end; end;
procedure TForm1.Button1Click(Sender: TObject); const ltrArray: array['A'..'Z'] of Char = ('9', 'B', 'C', 'D', '6', 'F', '7', 'H', 'I', 'J', 'K', '8', '1', '5', '4', 'P', 'Q', '2', 'S', 'T', '3', 'V', 'W', '0', 'Y', 'Z'); var I: Integer; begin Label1.Caption := ''; for I := 1 to Length(Edit1.Text) do if Edit1.Text[I] in ['A'..'Z'] then Label1.Caption := Label1.Caption + ltrArray[Edit1.Text[I]] else Label1.Caption := Label1.Caption + Edit1.Text[I]; end;
procedure TForm1.Button1Click(Sender: TObject); const ltrArray: array['A'..'Z'] of Char = ('9', 'B', 'C', 'D', '6', 'F', '7', 'H', 'I', 'J', 'K', '8', '1', '5', '4', 'P', 'Q', '2', 'S', 'T', '3', 'V', 'W', '0', 'Y', 'Z'); CharToShift = ['X','M','R','U','O','N','E','G','L','A']; // les caractères à modifier, les autres seront négligés var I: Integer; begin Label1.Caption := ''; if Length(Edit1.Text) > 9 then Exit; // longueur maxi for I := 1 to Length(Edit1.Text) do if Edit1.Text[I] in CharToShift then Label1.Caption := Label1.Caption + ltrArray[Edit1.Text[I]]; end;
j := 0; // ne sert à rien, déclaration de la variable "J" inutile également
array['A'..'Z'] of Char, c'est balaise !
procedure TForm1.Button1Click(Sender: TObject); const ltrArray: array['A'..'Z'] of Char = ('9', 'B', 'C', 'D', '6', 'F', '7', 'H', 'I', 'J', 'K', '8', '1', '5', '4', 'P', 'Q', '2', 'S', 'T', '3', 'V', 'W', '0', 'Y', 'Z'); var I: Integer; Z:string; begin Label1.Caption := ''; Z := uppercase(Edit1.Text=; for I := 1 to Length(Z) do if Z[I] in ['A'..'Z'] then Label1.Caption := Label1.Caption + ltrArray[Z[I]] else MessageDlg('Erreur, caractère ' = Z[i] =' incompatible',mtInformation,[mbOk],0); end;
Quand même, learray['A'..'Z'] of Char,
c'est balaise !
procedure TForm1.Edit1Change(Sender: TObject); const ltrArray: array['A'..'Z'] of Char = ('9', 'B', 'C', 'D', '6', 'F', '7', 'H', 'I', 'J', 'K', '8', '1', '5', '4', 'P', 'Q', '2', 'S', 'T', '3', 'V', 'W', '0', 'Y', 'Z'); var I: Integer; Z:string; begin IF edit1.GetTextLen<> 0 then begin Label1.Caption := ''; Z := uppercase(Edit1.Text); for I := 1 to Length(Z) do if Z[I] in ['X','M','R','U','O','N','E','G','L','A'] then Label1.Caption := Label1.Caption + ltrArray[Z[I]] else MessageDlg('Erreur, caractère ' + Z[i] +' incompatible',mtInformation,[mbOk],0); END; end;
3 mars 2018 à 23:11
Cherchez un raccourci ou une autre méthode si possible pour ne pas être répétitif