Designing Radio Buttons

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
AndrewT
Junior Coder
Posts: 37
Joined: Thu Sep 17, 2015 6:06 pm

Designing Radio Buttons

Post by AndrewT » Sun May 03, 2020 2:52 pm

I am trying to make two radio button objects dependent on each other, but I can't figure out how to reset or set a radio button from the code. I have tried to set the SelectedItem to null, an index value, and the actual value, but no luck.

What I need is two radio button objects that are dependent on each other as follows. The first radio button object has options A and B. The other radio button object has options 1, 2, and 3. Valid combinations are A1, B2, and B3. So if the user tries to select A2, A3, or B1, I would like to reset the radion buttons to null.

I found an old post about using ResetDialogAction, but the documentation says that this command has been Depreciated. So I guess I am looking for suggestions.

Thanks,
Andrew T

User avatar
Grovkillen
Automation Wizard
Posts: 665
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Designing Radio Buttons

Post by Grovkillen » Sun May 03, 2020 4:22 pm

They need to be in the same group.
Let>ME=%Script%

Running: 15.0.18
version history

User avatar
JRL
Automation Wizard
Posts: 3396
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Designing Radio Buttons

Post by JRL » Mon May 04, 2020 4:18 pm

Not sure I have your logic perfect but here is an example

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 613
  Top = 189
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 185
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSRadioGroup1: tMSRadioGroup
    Left = 31
    Top = 14
    Width = 185
    Height = 105
    Caption = 'MSRadioGroup1'
    Items.Strings = (
      '1'
      '2')
    TabOrder = 8
    Text = '1'#13#10'2'#13#10
    Text = 'A'#13#10'B'
  end
  object MSRadioGroup2: tMSRadioGroup
    Left = 252
    Top = 14
    Width = 185
    Height = 105
    Caption = 'MSRadioGroup2'
    Items.Strings = (
      'A'
      'B'
      'C')
    TabOrder = 9
    Text = '1'#13#10'2'#13#10'3'
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,MSRadioGroup1,OnClick,CheckGroup1
AddDialogHandler>Dialog1,MSRadioGroup2,OnClick,CheckGroup2

Show>Dialog1,


SRT>CheckGroup1
  GetDialogProperty>Dialog1,MSRadioGroup1,ItemIndex,Index1Res
  GetDialogProperty>Dialog1,MSRadioGroup2,ItemIndex,Index2Res
  
  If>{("%Index1Res% %Index2Res%"="0 0")or("%Index1Res% %Index2Res%"="1 1")or("%Index1Res% %Index2Res%"="1 2")or(%Index1Res%=-1)or(%Index2Res%=-1)}
  Else
    SetDialogProperty>Dialog1,MSRadioGroup1,ItemIndex,-1
    SetDialogProperty>Dialog1,MSRadioGroup2,ItemIndex,-1
  EndIf
END>CheckGroup1


SRT>CheckGroup2
  GetDialogProperty>Dialog1,MSRadioGroup1,ItemIndex,Index1Res
  GetDialogProperty>Dialog1,MSRadioGroup2,ItemIndex,Index2Res
  
  If>{("%Index1Res% %Index2Res%"="0 0")or("%Index1Res% %Index2Res%"="1 1")or("%Index1Res% %Index2Res%"="1 2")or("%Index1Res% %Index2Res%"="1 2")or(%Index1Res%=-1)or(%Index2Res%=-1)}
  Else
    SetDialogProperty>Dialog1,MSRadioGroup1,ItemIndex,-1
    SetDialogProperty>Dialog1,MSRadioGroup2,ItemIndex,-1
  EndIf
END>CheckGroup2

AndrewT
Junior Coder
Posts: 37
Joined: Thu Sep 17, 2015 6:06 pm

Re: Designing Radio Buttons

Post by AndrewT » Mon May 04, 2020 6:34 pm

Thanks JRL!
The logic is basically what I had figured out, but it was the setting ItemIndex to -1 instead of the SelectedItem property that I needed.

Andrew T

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts