Function of Delphi works on windows but not on android

Asked

Viewed 844 times

4

I have two functions in my project, one for Cpf validation and another to remove different characters from numbers from the string; ok, when I run for windows it works perfectly. Already when I compile for android, I run the application on mobile it always invalidates Cpf and does not remove the characters from the string. Anyone has any idea?

Function that validates Cpf:

function TFmNovoCliente.ValidaCpf(num: string): boolean;
var
n1,n2,n3,n4,n5,n6,n7,n8,n9:integer;
d1,d2:integer;
digitado, calculado:string;
begin
   num:= removechar(num);
   n1:= StrToInt(num[1]);
   n2:= StrToInt(num[2]);
   n3:= StrToInt(num[3]);
   n4:= StrToInt(num[4]);
   n5:= StrToInt(num[5]);
   n6:= StrToInt(num[6]);
   n7:= StrToInt(num[7]);
   n8:= StrToInt(num[8]);
   n9:= StrToInt(num[9]);
   d1:= n9*2+n8*3+n7*4+n6*5+n5*6+n4*7+n3*8+n2*9+n1*10;
   d1:= 11-(d1 mod 11);
   if d1>=10 then d1:=0;
   d2:= d1*2+n9*3+n8*4+n7*5+n6*6+n5*7+n4*8+n3*9+n2*10+n1*11;
   d2:= 11-(d2 mod 11);
   if d2>=10 then d2:=0;
   calculado:= inttostr(d1)+inttostr(d2);
   digitado:= num[10]+num[11];
   if calculado = digitado then
      result:=false
   else
      result:=true;
end;

Function removes characters

function TFmNovoCliente.removechar(Texto :String):String;
var
I: integer;
S: string;
begin
   S := '';
   for I := 1 To Length(Texto) Do
   begin
      if (Texto[I] in ['0'..'9']) then
      begin
         S := S + Copy(Texto, I, 1);
      end;
   end;
   result := S;
end;

1 answer

5

Good guys, I discovered the mistake.

In case someone falls here with the same mistake;

By default Delphi has its string started in string[1], whereas in android the string starts in string[0];

just add this {$ZEROBASEDSTRINGS OFF} to standardize;

  • And it should be put on that part of the code?

  • 1

    after uses and {$R *.fmx}

  • GREAT TIP. I WILL TEST YOU HAVE NO IDEA HOW I HIT MY HEAD WITH THIS...

Browser other questions tagged

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