Checkboxes behaving sporadically

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Checkboxes behaving sporadically

Post by Phil Pendlebury » Tue Apr 12, 2022 1:32 pm

I have a dialog which has 40 checkboxes
They are populated by an ini file and then some are disabled etc.

There is a section in my code where I have to reset all 40 checkboxes by enabling them and then clearing the checks.
I am finding that if I use a loop to do this, it simply does not work (some boxes remain disabled for example), unless I put a big delay in the loop
So I have a list of all 40 checkboxes but even that sometimes seem to fail.

I have got round this by adding waits between sections of actions, for example:

Code: Select all

SetDialogProperty>OBSChecklist1,CheckBox1,Enabled,True
(repeated 40 times)
Wait>0.1
SetDialogProperty>OBSChecklist1,CheckBox1,Checked,False
(repeated 40 times)
My code is now just a huge amount of repeated lines with 1 number different, it is such a shame.

Is this a known issue I wonder that changing checkbox states (when in large amounts) can be sluggish? Maybe I should have been aware of it.

This is not a complaint btw just a genuine question.
Phil Pendlebury - Linktree

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

Re: Checkboxes behaving sporadically

Post by JRL » Tue Apr 12, 2022 7:04 pm

Hi Phil,
Never noticed that type of issue. I threw together the following to test. Pick the "Flipping Checkboxes" button and whatever state each checkbox is in will be reversed. Pick the "Enable / Disable" button and any checkbox that is checked will be disabled. I don't see any issues. That said your issue might be the result of other objects in the dialog or other code in your script hogging memory.

I did a test years ago probably back under WinXP to see if a large number of dialog objects caused any problems such as slow response or even visibility problems. I discovered that you had to have thousands of objects before there was a significant issue. In my test once there were issues, adding just a few objects more locked up MS completely. In any case, I would not expect 40 checkboxes to cause problems.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 545
  Top = 176
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 615
  ClientWidth = 406
  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 CheckBox1: TCheckBox
    Left = 37
    Top = 8
    Width = 97
    Height = 17
    Caption = 'CheckBox1'
    TabOrder = 0
  end
  object CheckBox2: TCheckBox
    Left = 37
    Top = 34
    Width = 97
    Height = 17
    Caption = 'CheckBox2'
    TabOrder = 1
  end
  object CheckBox3: TCheckBox
    Left = 37
    Top = 60
    Width = 97
    Height = 17
    Caption = 'CheckBox3'
    TabOrder = 2
  end
  object CheckBox4: TCheckBox
    Left = 37
    Top = 86
    Width = 97
    Height = 17
    Caption = 'CheckBox4'
    TabOrder = 3
  end
  object CheckBox5: TCheckBox
    Left = 37
    Top = 112
    Width = 97
    Height = 17
    Caption = 'CheckBox5'
    TabOrder = 4
  end
  object CheckBox6: TCheckBox
    Left = 37
    Top = 138
    Width = 97
    Height = 17
    Caption = 'CheckBox6'
    TabOrder = 5
  end
  object CheckBox7: TCheckBox
    Left = 37
    Top = 164
    Width = 97
    Height = 17
    Caption = 'CheckBox7'
    TabOrder = 6
  end
  object CheckBox8: TCheckBox
    Left = 37
    Top = 190
    Width = 97
    Height = 17
    Caption = 'CheckBox8'
    TabOrder = 7
  end
  object CheckBox9: TCheckBox
    Left = 37
    Top = 216
    Width = 97
    Height = 17
    Caption = 'CheckBox9'
    TabOrder = 8
  end
  object CheckBox10: TCheckBox
    Left = 37
    Top = 242
    Width = 97
    Height = 17
    Caption = 'CheckBox10'
    TabOrder = 9
  end
  object CheckBox11: TCheckBox
    Left = 37
    Top = 268
    Width = 97
    Height = 17
    Caption = 'CheckBox11'
    TabOrder = 10
  end
  object CheckBox12: TCheckBox
    Left = 37
    Top = 294
    Width = 97
    Height = 17
    Caption = 'CheckBox12'
    TabOrder = 11
  end
  object CheckBox13: TCheckBox
    Left = 37
    Top = 320
    Width = 97
    Height = 17
    Caption = 'CheckBox13'
    TabOrder = 12
  end
  object CheckBox14: TCheckBox
    Left = 37
    Top = 346
    Width = 97
    Height = 17
    Caption = 'CheckBox14'
    TabOrder = 13
  end
  object CheckBox15: TCheckBox
    Left = 37
    Top = 372
    Width = 97
    Height = 17
    Caption = 'CheckBox15'
    TabOrder = 14
  end
  object CheckBox16: TCheckBox
    Left = 37
    Top = 398
    Width = 97
    Height = 17
    Caption = 'CheckBox16'
    TabOrder = 15
  end
  object CheckBox17: TCheckBox
    Left = 37
    Top = 424
    Width = 97
    Height = 17
    Caption = 'CheckBox17'
    TabOrder = 16
  end
  object CheckBox18: TCheckBox
    Left = 37
    Top = 450
    Width = 97
    Height = 17
    Caption = 'CheckBox18'
    TabOrder = 17
  end
  object CheckBox19: TCheckBox
    Left = 37
    Top = 476
    Width = 97
    Height = 17
    Caption = 'CheckBox19'
    TabOrder = 18
  end
  object CheckBox20: TCheckBox
    Left = 37
    Top = 502
    Width = 97
    Height = 17
    Caption = 'CheckBox20'
    TabOrder = 19
  end
  object CheckBox21: TCheckBox
    Left = 279
    Top = 4
    Width = 97
    Height = 17
    Caption = 'CheckBox21'
    TabOrder = 20
  end
  object CheckBox22: TCheckBox
    Left = 279
    Top = 30
    Width = 97
    Height = 17
    Caption = 'CheckBox22'
    TabOrder = 21
  end
  object CheckBox23: TCheckBox
    Left = 279
    Top = 56
    Width = 97
    Height = 17
    Caption = 'CheckBox23'
    TabOrder = 22
  end
  object CheckBox24: TCheckBox
    Left = 279
    Top = 82
    Width = 97
    Height = 17
    Caption = 'CheckBox24'
    TabOrder = 23
  end
  object CheckBox25: TCheckBox
    Left = 279
    Top = 108
    Width = 97
    Height = 17
    Caption = 'CheckBox25'
    TabOrder = 24
  end
  object CheckBox26: TCheckBox
    Left = 279
    Top = 134
    Width = 97
    Height = 17
    Caption = 'CheckBox26'
    TabOrder = 26
  end
  object CheckBox27: TCheckBox
    Left = 279
    Top = 160
    Width = 97
    Height = 17
    Caption = 'CheckBox27'
    TabOrder = 28
  end
  object CheckBox28: TCheckBox
    Left = 279
    Top = 186
    Width = 97
    Height = 17
    Caption = 'CheckBox28'
    TabOrder = 30
  end
  object CheckBox29: TCheckBox
    Left = 279
    Top = 212
    Width = 97
    Height = 17
    Caption = 'CheckBox29'
    TabOrder = 32
  end
  object CheckBox30: TCheckBox
    Left = 279
    Top = 238
    Width = 97
    Height = 17
    Caption = 'CheckBox30'
    TabOrder = 34
  end
  object CheckBox31: TCheckBox
    Left = 279
    Top = 264
    Width = 97
    Height = 17
    Caption = 'CheckBox31'
    TabOrder = 36
  end
  object CheckBox32: TCheckBox
    Left = 279
    Top = 290
    Width = 97
    Height = 17
    Caption = 'CheckBox32'
    TabOrder = 38
  end
  object CheckBox33: TCheckBox
    Left = 279
    Top = 316
    Width = 97
    Height = 17
    Caption = 'CheckBox33'
    TabOrder = 40
  end
  object CheckBox34: TCheckBox
    Left = 279
    Top = 342
    Width = 97
    Height = 17
    Caption = 'CheckBox34'
    TabOrder = 25
  end
  object CheckBox35: TCheckBox
    Left = 279
    Top = 368
    Width = 97
    Height = 17
    Caption = 'CheckBox35'
    TabOrder = 27
  end
  object CheckBox36: TCheckBox
    Left = 279
    Top = 394
    Width = 97
    Height = 17
    Caption = 'CheckBox36'
    TabOrder = 29
  end
  object CheckBox37: TCheckBox
    Left = 279
    Top = 420
    Width = 97
    Height = 17
    Caption = 'CheckBox37'
    TabOrder = 31
  end
  object CheckBox38: TCheckBox
    Left = 279
    Top = 446
    Width = 97
    Height = 17
    Caption = 'CheckBox38'
    TabOrder = 33
  end
  object CheckBox39: TCheckBox
    Left = 279
    Top = 472
    Width = 97
    Height = 17
    Caption = 'CheckBox39'
    TabOrder = 35
  end
  object CheckBox40: TCheckBox
    Left = 279
    Top = 498
    Width = 97
    Height = 17
    Caption = 'CheckBox40'
    TabOrder = 37
  end
  object MSButton1: tMSButton
    Left = 143
    Top = 533
    Width = 114
    Height = 25
    Caption = 'Flipping CheckBoxes'
    TabOrder = 39
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 148
    Top = 574
    Width = 109
    Height = 25
    Caption = 'Enable / Disable'
    TabOrder = 49
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,MSButton1,OnClick,srtFlip
AddDialogHandler>Dialog1,MSButton2,OnClick,srtEnableDisable
Show>Dialog1,

SRT>srtFlip
  Let>kk=0
  Repeat>kk
    Add>kk,1
    GetDialogProperty>Dialog1,CheckBox%kk%,Checked,res
    If>res=True
      SetDialogProperty>Dialog1,CheckBox%kk%,Checked,False
    Else
      SetDialogProperty>Dialog1,CheckBox%kk%,Checked,True
    EndIf
  Until>kk=40
END>srtFlip


SRT>srtEnableDisable
    Let>ee=0
  Repeat>ee
    Add>ee,1
    GetDialogProperty>Dialog1,CheckBox%ee%,Checked,res
    If>res=True
      SetDialogProperty>Dialog1,CheckBox%ee%,Enabled,False
    Else
      SetDialogProperty>Dialog1,CheckBox%ee%,Enabled,True
    EndIf
  Until>ee=40
END>srtEnableDisable

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Checkboxes behaving sporadically

Post by Grovkillen » Tue Apr 12, 2022 8:02 pm

Do you check if the checkbox need to change its state? Maybe setting a checkbox to its current state is creating a bit of lag?
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Checkboxes behaving sporadically

Post by Phil Pendlebury » Wed Apr 13, 2022 5:02 am

Cheers guys,

I suspect then that my code is less than efficient.

:D
Phil Pendlebury - Linktree

User avatar
Djek
Pro Scripter
Posts: 147
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: Checkboxes behaving sporadically

Post by Djek » Fri Nov 11, 2022 3:56 pm

Hi all,

I once had an "strange" problem with checkboxes.
In a routine I needed a button that i could click, if I wanted to refresh variables i a program.
And this action should be visible until the refresh was done (about 3 seconds)
So if this was a Button, I would change Color to Red to indicate that the process was running.
And after running the Button returns normal color.
But a Button can not change color, so i used a checkbox instead.
And now the circus started.....

Code: Select all


//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
//Checkbox test

Dialog>Dialog1
object Dialog1: TForm
  Left = 438
  Top = 165
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 223
  ClientWidth = 484
  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 CheckBox3: TCheckBox
    Left = 74
    Top = 86
    Width = 97
    Height = 17
    Caption = 'CheckBox3'
    TabOrder = 0
  end
end
EndDialog>Dialog1


AddDialogHandler>dialog1,checkbox3,OnClick,DoRefresh
AddDialogHandler>Dialog1,,OnClose,DoClose
 
Show>Dialog1

let>VarRefresh=0
let>Terminated=False
label>WaitForAction

if>VarRefresh=1
  let>VarRefresh=0
  SetDialogProperty>Dialog1,Checkbox3,Checked,True
  Message>-
  Message>now refreshing variables routine !!
  wait>1
  Message>-
  SetDialogProperty>Dialog1,Checkbox3,Checked,False
endif

if>Terminated=True
  CloseDialog>Dialog1
  goto>closeprogramm
endif

wait>2
goto>WaitForAction

SRT>DoClose
 Let>Terminated=True
End>DoClose
 
SRT>DoRefresh
  Let>VarRefresh=1
END>DoRefresh

Label>closeprogramm

The Dialog starts,
shows a checkbox
if you click on the checkbox, a SRT set variable VarRefresh to 1
In the main loop, I see that the VarRefresh is 1 (active) .
The first thing I do, is setting the VarRefresh to 0
Than I refresh my variables
And then I return to the main loop....

See what happens !
The loop keeps on going refreshing !!



SPOILER ALERT do not read below this line if you want to find the cause yourself !!



---------------------------------------------------------------------------------



The dialoghandler got activated each time you run
SetDialogProperty>Dialog1,Checkbox3,Checked,True
This fires SRT>DoRefresh (so the "Checked" activates a "OnClick" event)
well this all is not shocking, but it kept me busy for while because I was debugging it, and while debugging the variable VarRefresh was (stepping with F8) always the right value, but running it "live" it kept in a loop.

Hope this helps you with your problem with the Checkboxes

Kind regards,
Djek

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