Error comparing strings in Delphi

Asked

Viewed 143 times

-2

I’m using the code:

conexao.First;
while not conexao.Eof do
  begin
  if (conexao.FieldValues['complex'] = '02' and conexao.FieldValues['financ'] = '04') then
    total24:= total24 + conexao.FieldValues['val_tot'];
  conexao.Next;
  end;

Along those lines if (conexao.FieldValues['complex'] = '02' and conexao.FieldValues['financ'] = '04') then I get the following error:

Incompatible types: 'string' and 'Boolean'

Because?

  • conexao is of what class?

  • is a table, lists the fields of a table. I will expand the code

  • so I know it’s a table, I want to know what it is, if it’s a dbx, firedac etc...

  • hi @Júniormoreira, I managed to solve. Thanks

2 answers

2

Generally FieldValues['NOME_FIELD'] results is a Variant, without a suitable Typecast can result in errors exactly like this one.

The correct is you enter the field name and type, follow example.

NOME_TABELA.FieldByName('NOME_FIELD').AsString = '02'
NOME_TABELA.FieldByName('NOME_FIELD').AsInteger = 02
NOME_TABELA.FieldByName('NOME_FIELD').AsBoolean = True

And so on and so forth.

0


The solution is just to separate the comparisons using parentheses:

if ((conexao.FieldValues['complex'] = '02') and (conexao.FieldValues['financ'] = '04')) then

Browser other questions tagged

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