Recent

Author Topic: Confirm checkbox check  (Read 716 times)

Jonny

  • Full Member
  • ***
  • Posts: 144
Confirm checkbox check
« on: February 23, 2025, 02:31:08 am »
I would like to verify a change to a checkbox state. So for now I am testing with a dialogbox. If the user selects yes then all if fine but if no is selected then the message appears twice. Is there another way to do this?

Also, I want the yes button to appear first (on the left) but it always shows as the second button.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.CheckBox1Click(Sender: TObject);
  2. begin
  3.   if QuestionDlg('Confirm','Do you understand?',mtWarning,[mrYes,'I Understand',mrNo,'Not really','IsDefault'],0) = mrNo then
  4. // both of these lines behave the same
  5. //  CheckBox1.Checked := False;
  6.     CheckBox1.State := cbUnchecked;
  7. end;
  8.  
  9. procedure TForm1.CheckBox1Change(Sender: TObject);
  10. begin
  11.   // same result with OnChange
  12. end;
  13.  

paweld

  • Hero Member
  • *****
  • Posts: 1598
Re: Confirm checkbox check
« Reply #1 on: February 23, 2025, 06:55:14 am »
Just assign to the OnChange event, and to exclude a double question dialog check what the selection status is.
As for the buttons, in my case it is as you write, i.e. “yes” as the first on the left, but you can manipulate the order of the buttons by changing the order in the array.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.CheckBox1Change(Sender: TObject);
  2. begin
  3.   if CheckBox1.Checked and (QuestionDlg('Confirm', 'Do you understand?', mtWarning, [mrNo, 'Not really', 'IsDefault', mrYes, 'I Understand'], 0) = mrNo) then
  4.     CheckBox1.Checked := False;
  5. end;
Best regards / Pozdrawiam
paweld

Jonny

  • Full Member
  • ***
  • Posts: 144
Re: Confirm checkbox check
« Reply #2 on: February 23, 2025, 12:18:16 pm »
Quote from: paweld
Code: Pascal  [Select][+][-]
  1. if CheckBox1.Checked ...

Of course, thank you @paweld.

Quote from: paweld
As for the buttons, in my case it is as you write, i.e. “yes” as the first on the left, but you can manipulate the order of the buttons by changing the order in the array.

Ah, they are in reverse, first in array is rightmost on dialog - at least on GTK2.

 

TinyPortal © 2005-2018