Recent

Author Topic: [SOLVED] How to get the value of a Boolean field  (Read 1948 times)

Hopestation

  • Full Member
  • ***
  • Posts: 157
[SOLVED] How to get the value of a Boolean field
« on: January 24, 2016, 08:12:25 pm »
Hi.

I was using a character field to hold boolean data, (Ticked,C,1) in a .dbf database.

I used: if dbf.fields[N].text = 'Y' to find the records I wanted.

Now I've changed the field to Boolean, (Ticked,L) and changed the "Ys" to TRUE.

I can't find out how to do the same search.

I've set the Field definition to ftBoolean and I get a column of tick boxes in the DBFGrid, with ticks where the "Ys" used to be.

As this is no longer a text field I omitted ".text" from the if statement.

Compiling   if dbf.fields[N] gives the error:
 
    unit1.pas(56,19) Error: Boolean expression expected, but got "TField".

Compiling    if dbf.fields[N] = true; gives the same error.

What is the correct way to do this?

Also, what is the correct way to set and reset the logical status?

Thanks.
« Last Edit: January 25, 2016, 12:02:59 pm by Hopestation »

FTurtle

  • Sr. Member
  • ****
  • Posts: 259
Re: How to get the value of a Boolean field
« Reply #1 on: January 24, 2016, 08:42:11 pm »
Code: Pascal  [Select]
  1. if dbf.fields[N].AsBoolean then

Hopestation

  • Full Member
  • ***
  • Posts: 157
Re: How to get the value of a Boolean field
« Reply #2 on: January 24, 2016, 11:38:10 pm »
Thanks for your help. It has solved the problem of the IF statement.

Based on that I used:     dbf.Fields[N].AsBoolean := true; to change the record from False to True but nothing happened.

I can toggle the state of the boolean field on the DBGrid by repeated clicking on it, but the run-time code is ignored.

I have obviously missed something here but I can't see what it is.

FTurtle

  • Sr. Member
  • ****
  • Posts: 259
Re: How to get the value of a Boolean field
« Reply #3 on: January 25, 2016, 07:37:27 am »
Based on that I used:     dbf.Fields[N].AsBoolean := true; to change the record from False to True but nothing happened.

You may have forgotten about Edit/Post:

Code: Pascal  [Select]
  1.   dbf.Edit;
  2.   dbf.Fields[N].AsBoolean :=
  3.   // editing of other fields
  4.   dbf.Post;
  5.  

Hopestation

  • Full Member
  • ***
  • Posts: 157
Re: How to get the value of a Boolean field
« Reply #4 on: January 25, 2016, 12:02:16 pm »
Thanks again.

It is a while since I worked with a DBF and I had overlooked this.