Esse código converte cada letra em valores pré estabelecidos pela função
Eu digito no edit e de forma automática vai aparecendo a conversão das letras no memo, um valor atrás da outra conforme vai se digitando no edit, e se clicando na tecla blackspace do teclado do pc dentro do edit ele vai limpando o memo .
no Edit digito por exemplo: Porto Alegre
e no Memo aparece: 76926 135795
Achei meio complicado o código de instruções ficar dentro do Editkeypress
Gostaria de saber se é possível otimizar esse código pra ficar mais coisas dentro da função e menos fora da função pra ficar fácil?
Att.
//////////////////////////////////////
function valor(x:string):string ;
var y,s,L:string;
i,i2:integer;
begin
result := '';
For i2:=0 to Length(x) do
for i:= 0 to Length(y) do
L:= Copy(x, i+i2, i2);
if L= #08 then y :=' 'else //#8 é a tecla Backspace pressionado
if L= #32 then y :='#'else //#32 é a tecla de espaço pressionado
if (L= 'A') or (L= 'a') or (L= 'Â') or (L= 'â') then y :='1'else
if (L= 'Ã') or (L= 'ã') or (L= 'Ä') or (L= 'ä') then y :='1'else
if (L= 'Á') or (L= 'á') or (L= 'À') or (L= 'à') then y :='1'else
if (L= 'J') or (L= 'j') then y :='1'else
if (L= 'S') or (L= 's') then y :='1'else
if (L= 'B') or (L= 'b') then y :='2'else
if (L= 'K') or (L= 'k') then y :='2'else
if (L= 'T') or (L= 't') then y :='2'else
if (L= 'C') or (L= 'c') or (L= 'Ç')or (L= 'ç') then y :='3'else
if (L= 'L') or (L= 'l') then y :='3'else
if (L= 'U') or (L= 'u') or (L= 'Ú')or (L= 'ú') or (L= 'Ù')then y :='3'else
if (L= 'ù') or (L= 'Û') or (L= 'û')or (L= 'Ü') or (L= 'ü')then y :='3'else
if (L= 'D') or (L= 'd')then y :='4'else
if (L= 'M') or (L= 'm')then y :='4'else
if (L= 'V') or (L= 'v')then y :='4'else
if (L= 'E') or (L= 'e')then y :='5'else
if (L= 'É') or (L= 'é')or (L= 'È')or (L= 'è')then y :='5'else
if (L= 'Ê') or (L= 'ê')or (L= 'Ë')or (L= 'ë')then y:='5'else
if (L= 'N') or (L= 'n')then y :='5'else
if (L= 'não') or (L= 'não')then y :='5'else
if (L= 'W') or (L= 'w')then y :='5'else
if (L= 'F') or (L= 'f')then y :='6'else
if (L= 'O') or (L= 'o')then y :='6'else
if (L= 'Õ') or (L= 'õ')then y :='6'else
if (L= 'Ó') or (L= 'ó')or (L= 'Ò')or (L= 'ò')or (L= 'Ô')or (L= 'Ö')or (L= 'ö')then y :='6'else
if (L= 'X') or (L= 'x')then y :='6'else
if (L= 'G') or (L= 'g')then y :='7'else
if (L= 'P') or (L= 'p')then y :='7'else
if (L= 'Y') or (L= 'y')then y :='7'else
if (L= 'H') or (L= 'h')then y :='8'else
if (L= 'Q') or (L= 'q')then y :='8'else
if (L= 'Z') or (L= 'z')then y :='8'else
if (L= 'I') or (L= 'i') or (L= 'Y') or (L= 'y') then y :='9'else
if (L= 'Í') or (L= 'í')or (L= 'Ì')or (L= 'ì')or (L= 'Î')or (L= 'î')or (L= 'Ï')or (L= 'ï')then y :='9'else
if (L= 'R') or (L= 'r')then y :='9';
result := Result+ y;
end;
procedure TForm1.Edit1Change(Sender: TObject);
var a:string; key:char;
begin
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var x:string;
i:integer;
begin
if (key = #8) then
begin
x:=Trim(Memo1.Lines.text);
delete(x,(length(x)+length(Edit1.Text))-length(Edit1.Text),1);
Delete(x, Length(x), 1);
Memo1.Text:=x;
end
else
exit;
end;
Question
tor 0
Olá amigos, saudações!
Esse código converte cada letra em valores pré estabelecidos pela função
Eu digito no edit e de forma automática vai aparecendo a conversão das letras no memo, um valor atrás da outra conforme vai se digitando no edit, e se clicando na tecla blackspace do teclado do pc dentro do edit ele vai limpando o memo .
no Edit digito por exemplo: Porto Alegre
e no Memo aparece: 76926 135795
Achei meio complicado o código de instruções ficar dentro do Editkeypress
Gostaria de saber se é possível otimizar esse código pra ficar mais coisas dentro da função e menos fora da função pra ficar fácil?
Att.
//////////////////////////////////////
function valor(x:string):string ;
var y,s,L:string;
i,i2:integer;
begin
result := '';
For i2:=0 to Length(x) do
for i:= 0 to Length(y) do
L:= Copy(x, i+i2, i2);
if L= #08 then y :=' 'else //#8 é a tecla Backspace pressionado
if L= #32 then y :='#'else //#32 é a tecla de espaço pressionado
if (L= 'A') or (L= 'a') or (L= 'Â') or (L= 'â') then y :='1'else
if (L= 'Ã') or (L= 'ã') or (L= 'Ä') or (L= 'ä') then y :='1'else
if (L= 'Á') or (L= 'á') or (L= 'À') or (L= 'à') then y :='1'else
if (L= 'J') or (L= 'j') then y :='1'else
if (L= 'S') or (L= 's') then y :='1'else
if (L= 'B') or (L= 'b') then y :='2'else
if (L= 'K') or (L= 'k') then y :='2'else
if (L= 'T') or (L= 't') then y :='2'else
if (L= 'C') or (L= 'c') or (L= 'Ç')or (L= 'ç') then y :='3'else
if (L= 'L') or (L= 'l') then y :='3'else
if (L= 'U') or (L= 'u') or (L= 'Ú')or (L= 'ú') or (L= 'Ù')then y :='3'else
if (L= 'ù') or (L= 'Û') or (L= 'û')or (L= 'Ü') or (L= 'ü')then y :='3'else
if (L= 'D') or (L= 'd')then y :='4'else
if (L= 'M') or (L= 'm')then y :='4'else
if (L= 'V') or (L= 'v')then y :='4'else
if (L= 'E') or (L= 'e')then y :='5'else
if (L= 'É') or (L= 'é')or (L= 'È')or (L= 'è')then y :='5'else
if (L= 'Ê') or (L= 'ê')or (L= 'Ë')or (L= 'ë')then y:='5'else
if (L= 'N') or (L= 'n')then y :='5'else
if (L= 'não') or (L= 'não')then y :='5'else
if (L= 'W') or (L= 'w')then y :='5'else
if (L= 'F') or (L= 'f')then y :='6'else
if (L= 'O') or (L= 'o')then y :='6'else
if (L= 'Õ') or (L= 'õ')then y :='6'else
if (L= 'Ó') or (L= 'ó')or (L= 'Ò')or (L= 'ò')or (L= 'Ô')or (L= 'Ö')or (L= 'ö')then y :='6'else
if (L= 'X') or (L= 'x')then y :='6'else
if (L= 'G') or (L= 'g')then y :='7'else
if (L= 'P') or (L= 'p')then y :='7'else
if (L= 'Y') or (L= 'y')then y :='7'else
if (L= 'H') or (L= 'h')then y :='8'else
if (L= 'Q') or (L= 'q')then y :='8'else
if (L= 'Z') or (L= 'z')then y :='8'else
if (L= 'I') or (L= 'i') or (L= 'Y') or (L= 'y') then y :='9'else
if (L= 'Í') or (L= 'í')or (L= 'Ì')or (L= 'ì')or (L= 'Î')or (L= 'î')or (L= 'Ï')or (L= 'ï')then y :='9'else
if (L= 'R') or (L= 'r')then y :='9';
result := Result+ y;
end;
procedure TForm1.Edit1Change(Sender: TObject);
var a:string; key:char;
begin
Memo1.Lines.Add(valor(Edit1.Text));
Memo1.Text:= StringReplace(Memo1.lines.text, #13#10, '', [rfReplaceAll]) ;
Memo1.Text:= StringReplace(Memo1.lines.text, '#', ' ', [rfReplaceAll]) ;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var x:string;
i:integer;
begin
if (key = #8) then
begin
x:=Trim(Memo1.Lines.text);
delete(x,(length(x)+length(Edit1.Text))-length(Edit1.Text),1);
Delete(x, Length(x), 1);
Memo1.Text:=x;
end
else
exit;
end;
Link to post
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.