I would like to type in Edit and the values of the letters appear in theTMemo using this function format

Asked

Viewed 42 times

0

I’d be very grateful if you could help me!

It only gives the value of the letter typed in Edit if I type one
time, if I try two or more gives error, I would like to know in
that I’m wrong, I’d like to show the value of the letter
repeatedly as you type it into Edit.


digitaria no teclado: zAAAAAB zzzz
no Edit exibiria: 5111111 5555

function m (x:string):string;
   var y:string;
   z,w:integer;
   begin
   if(x='A') or (x ='a') or (x='Â') or (x='â') or (x='ã') then y :='1';
   if(x='b') then y:='1';
   if(x='c') then y:='1';
   if(x='z') then y:='5';
  ......

Result:='';
for w:=1 to Length(x) do
begin
z:=0;
repeat z:=z+1;
until x[z]=x[z];
Result:=Result+y[w];
end;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
memo1.text:=(m(edit1.text));
end;

  • I think the z variable and looping with repeat/until are unnecessary and if you repair the z variable is not being used to mount the result.

  • And the Ifs to assign a value to the variable y must stay within the looping for/do to evaluate each character of the string x and for that the variable w must be used as Indice. The y variable must be used without index since it will always have a single character. Also consider adding code to add some value to the variable y when the evaluated character is different from all that are predicted.

  • hi imex, thanks for your tips, wow, I’m having a lot of work and difficulty to assemble this function alone I started in programming studies a short time, I’m still an apprentice, I would code in html, you could help me if it’s too much trouble?

1 answer

1


Follow a code suggestion for studies and tests:

function m(x:string): string;
var
  y: string;
  w: integer;
begin
  Result := '';
  for w := 1 to Length(x) do
    begin
      if (x[w] = 'A') or 
         (x[w] = 'a') or 
         (x[w] = 'Â') or 
         (x[w] = 'â') or 
         (x[w] = 'ã') or
         (x[w] = 'b') or
         (x[w] = 'c') then
        y := '1'
      else
        if x[w] = 'z' then 
          y := '5'
        else
          y := ' ';
      Result := Result + y;
    end;
end;

The looping For/Do is used to access each character of the string separately, and within the looping a sequence of Ifs is used to assign a value to the variable y according to the value of that character, and then the value of variable y is concatenated to form the result returned by the function.

I hope it helps

  • Hi Imex! Help yes, how nice it was that I was in need, thank you very much, very happy, God pay you.

  • I’m glad the answer helped. Kindly assess the possibility of accepting it as an answer.

  • It helped a lot yes, thank you very much, I accept yes as an answer, it is answered and solved, thank you very much, att.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.