Can the entire variable receive a conditional value?

Asked

Viewed 58 times

1

I have a situation where something like this happens:

procedure FrmTeste.Teste;
var
   iSinc: LongInt;
const
   ACAO_PROX: LongInt = $0008;
begin
   iSinc := iSinc or ACAO_PROX;
end;

I couldn’t figure out what amount iSinc gets when entering this function, which actually happens?

1 answer

1


This variable will receive a value BOOLEANO, such an assignment would be the same as:

if (iSinc or ACAO_PROX) then
  iSinc := True
else
  iSinc := False;

If you do the conversion, the answer will be TRUE or FALSE:

procedure FrmTeste.Teste;
var
   iSinc: LongInt;
const
   ACAO_PROX: LongInt = $0008;
begin
   iSinc := iSinc or ACAO_PROX;
   ShowMessage(BoolToStr(Boolean(iSinc)));
end;
  • But what it means to make this comparison, what it will say if iSinc is true, or Acao_prox is true?

  • I edited the answer

  • All right, I got it so far, but what I want to know is: iSinc can be true by being a positive integer?

  • @William does not know Delphi, but C and other languages assume that 0 is false and anything else is true. So if Delphi assumes this behavior as well, a numeric can be treated as boolean

  • Exactly that @Jeffersonquesado no Delphi é mesma coisa, 0 é false e qualquer outro número inteiro é true

Browser other questions tagged

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