Recent

Author Topic: Testing Radio Group  (Read 3863 times)

J-G

  • Hero Member
  • *****
  • Posts: 953
Testing Radio Group
« on: September 27, 2016, 12:37:12 pm »
I can see how to test for a RadioButton.Checked and with a group I know that they are mutually exclusive.

With this in mind I feel that there ought to be a simple way to determine which of (say) 4 buttons has been selected. I could of course do a simple If - then - else cascade on each but that seems to be a crude method.

Is there a more elegant method?
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

wp

  • Hero Member
  • *****
  • Posts: 11910
Re: Testing Radio Group
« Reply #1 on: September 27, 2016, 12:47:19 pm »
RadioGroup.ItemIndex

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: Testing Radio Group
« Reply #2 on: September 27, 2016, 01:00:15 pm »
RadioGroup.ItemIndex

I did look at that WP, thanks, but when I tried to set it to '1' (selecting the first button as default) it threw up an error 'Out of bounds  0...-1'  so I had to resort to setting the 'checked' property of the first button to 'true'. - I did see that all others were automatically set to 'false'.

Am I to understand that it will be set at run-time to 1,2,3 or 4 (in the case of a group of 4) or even 0,1,2 or 3   so I can do a 'case RadioGroup.ItemIndex of ...' ?
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

wp

  • Hero Member
  • *****
  • Posts: 11910
Re: Testing Radio Group
« Reply #3 on: September 27, 2016, 01:16:20 pm »
I tried to set it to '1' (selecting the first button as default) it threw up an error 'Out of bounds  0...-1' 
Index values begin at 0. So, if you want to select the "first" radio button you must use Itemindex 0 - always one less than natural language...

And I don't know how you set up the radiogroup: Don't add inidivual radiobuttons to the RadioGroup. Just add the button texts to the Items property of the RadioGroup. Every line in the editor dialog automatically adds a button.

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: Testing Radio Group
« Reply #4 on: September 27, 2016, 01:35:32 pm »
I tried to set it to '1' (selecting the first button as default) it threw up an error 'Out of bounds  0...-1' 
Index values begin at 0. So, if you want to select the "first" radio button you must use Itemindex 0 - always one less than natural language...

And I don't know how you set up the radiogroup: Don't add inidivual radiobuttons to the RadioGroup. Just add the button texts to the Items property of the RadioGroup. Every line in the editor dialog automatically adds a button.

AH...  Thanks WP
Of course I added individual radio buttons  -  that seemed logical  - ;D   I've now sorted the issue and even arranged the buttons horizontally. Sometimes there are so many 'properties' available that it becomes difficult to see the wood for the trees!!
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

 

TinyPortal © 2005-2018