-1
I’ve literally been looking at this piece of code since yesterday trying to figure out why the for
is not passing 0. I have tried several ways, and already confirmed that I am always adding one more number to it, but simply it stops at 0.
What I want to do is this: I will always add a sequence of numbers within a Tedit
and then press to send them. Only the numbers entered can never be smaller or equal to the numbers previously sent.
Can someone give me a hand? I’m using Delphi RIO
and I’m developing an app for ANDROID
Here is my code:
procedure TF_dianteira.bt_OKEClick(Sender: TObject);
var
i: integer;
hora_texto: string;
funcionou_menor: string;
funcionou_igual: string;
begin
funcionou_menor := 'sim';
funcionou_igual := 'sim';
ShowMessage('vai ate ' +IntToStr(Emb_Maximo));
for i := 0 to Emb_Maximo do
begin
ShowMessage(IntToStr(i));
if (StrToInt(txt_embarque_d.Text) < vetor[i]) then
begin
ShowMessage('Numero: ' +txt_embarque_d.Text);
ShowMessage('Numero anteriormente digitado: ' + IntToStr(vetor[i]));
ShowMessage('Não pode haver senhas menores que anteriores');
funcionou_menor := 'nao';
txt_embarque_d.Text := '';
break;
end
else
begin
funcionou_menor := 'sim';
end;
if (StrToInt(txt_embarque_d.Text) = vetor[i]) then
begin
ShowMessage('Não pode haver senhas iguais à anteriores');
txt_embarque_d.Text := '';
funcionou_igual := 'nao';
break;
end
else
begin
funcionou_igual := 'sim';
end;
if (funcionou_menor = 'sim') then
begin
if (funcionou_igual = 'sim') then
begin
if i <> 0 then
SetLength(vetor, Length(vetor));
vetor[Emb_Maximo] := StrToInt(txt_embarque_d.Text);
ShowMessage('Vetor adicionado ' +IntToStr(vetor[Emb_Maximo]) );
//Aqui eu vou criar um arquivo
txt_embarque_d.Text := '';
Emb_Maximo := Emb_Maximo + 1;
break;
end;
end;
continue
end;
end;
It’s been a while since I stopped programming on pascal Object, but if I’m not mistaken You need to force the increment of your variable "i", something like
... continue; i = i + 1;
, I can’t remember but try it there– Armando Marques Sobrinho
I tried to put one
continue
there at the end, give a look to you see, but remains the same problem = andi := i+1;
does not work because it says that I am setting value to a variable of afor
– user3602803
with what value starts var Emb_maximo ? because it’s only increasing it in some situations... so if it starts at 0, it probably only does 1 or 2 iterations...
– Tiago Rodrigues
It starts with 0, but only increases if you’ve actually added some value, that’s the intention you know? for example, if I inserted "1", in the future, if I insert "1" I cannot give. but if I insert "2", you have to give, then Emb_maximo has to increase a value because you added one more in the vector
– user3602803
It’s hard to understand your code. There are global variables, so you can’t understand the context. But, it has a few things: if i <> 0 then Setlength(vector, Length(vector)); Do you notice that this code does nothing? Emb_maximo := Emb_maximo + 1; . continue remove this line, this command only makes sense if you need to go back to the beginning of the looping in the middle of processing, ignoring additional lines. in this case, there are no additional lines to ignore, as the command is at the end of the looping.
– Ricardo Alves Carvalho
if i< > 0 then setLength
is because I just want to increase the size of the vector after thefor
is no longer 0– user3602803
before the is assigned 0 or the start value of its variable i, and at the beginning of the for an inc(i) to add one each time it goes through the for.
– Michel Ailton