Recent

Author Topic: [SOLVED] CheckBox, not getting expected result  (Read 3912 times)

Elmug

  • Hero Member
  • *****
  • Posts: 849
[SOLVED] CheckBox, not getting expected result
« on: July 20, 2012, 04:54:21 am »
Hi everyone.

I put CheckBox1 on Form1.

And OnFormActivate, these line is the code:
  CheckBox1.Enabled := SQLQuery1.Active;  {Valid, since both are booleans}

The expected result is that CheckBox1 should appear CHECKED, since I have set the SQLQuery1 Active = True by design, but CheckBox1 shows UNCHECKED.

How come this is so?

PS: I want to start monitoring status of components relating to database use, in order to figure certain things out.

Thanks!



« Last Edit: July 21, 2012, 04:43:33 pm by Elmug »

paweld

  • Hero Member
  • *****
  • Posts: 1003
Re: CheckBox, not getting expected result
« Reply #1 on: July 20, 2012, 06:16:07 am »
move
Code: [Select]
CheckBox1.Enabled := SQLQuery1.Active; from Form1.OnActivate to SQLQuery1.AfterOpen
Best regards / Pozdrawiam
paweld

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: CheckBox, not getting expected result
« Reply #2 on: July 20, 2012, 06:37:17 am »
move
Code: [Select]
CheckBox1.Enabled := SQLQuery1.Active; from Form1.OnActivate to SQLQuery1.AfterOpen

Hi and thanks for helping, paweld.

I tried your suggestion and it did not work.

In fact, the problem seems to me, is in the equating of the two entities, for I have even tried activating the same one line of code with a pushbutton, and the checkbox does not show "checked".

In fact, also, with the same button I change the caption of a label (to detect the state) and that does work, of course, meaning the code to set the label value and the one line of code using the booleans is in the same block of code to the onclick of the button.

Any explanations, or corrections?

P.S. I am coming to believe that even though they both are booleans, the booleans are not compatible.

Thanks!
« Last Edit: July 20, 2012, 06:40:36 am by Elmug »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: CheckBox, not getting expected result
« Reply #3 on: July 20, 2012, 07:07:19 am »
Hi everyone.

I put CheckBox1 on Form1.

And OnFormActivate, these line is the code:
  CheckBox1.Enabled := SQLQuery1.Active;  {Valid, since both are booleans}

The expected result is that CheckBox1 should appear CHECKED, since I have set the SQLQuery1 Active = True by design, but CheckBox1 shows UNCHECKED.

Well Enabled is not used to control the check box's state. Try setting the Checked instead.
Code: [Select]
  CheckBox1.Checked := SQLQuery1.Active;   

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: CheckBox, not getting expected result
« Reply #4 on: July 20, 2012, 07:30:58 am »
Well Enabled is not used to control the check box's state. Try setting the Checked instead.
Code: [Select]
  CheckBox1.Checked := SQLQuery1.Active; 

Hi Taazz and thanks!

You are most correct. It does it. :)

And, poweld, I DID relocate the action to SQLQuery1.AfterOpen, which is a much better place to have it. And I also trigger that one line by code, from other procedures, to refresh the checkbox.
« Last Edit: July 20, 2012, 07:45:35 am by Elmug »

 

TinyPortal © 2005-2018