Dialog Handler Anomaly

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
arobin4
Junior Coder
Posts: 33
Joined: Sat Apr 07, 2012 5:41 am

Dialog Handler Anomaly

Post by arobin4 » Thu May 17, 2012 3:21 am

Hi Forum:
Please offer your insight. In below script, I expected the message modal box to appear only once when clicking on Checkbox1. However, the message modal box appears twice. It seems like the dialog handler is firing for Checkbox2 even though the box was not Clicked (per the OnClick event). Am I understanding the expected behavior correctly?

Dialog>Dialog1
object Dialog1: TForm
Left = 306
Top = 98
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 223
ClientWidth = 439
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 = 57
Top = 20
Width = 97
Height = 17
Caption = 'CheckBox1'
Checked = True
State = cbChecked
TabOrder = 8
end
object CheckBox2: TCheckBox
Left = 57
Top = 119
Width = 97
Height = 17
Caption = 'CheckBox2'
TabOrder = 9
end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,CheckBox1,OnClick,DisEnableLogs
AddDialogHandler>Dialog1,CheckBox2,OnClick,DisEnableLogs

show>dialog1,r

SRT>DisEnableLogs
getDialogProperty>Dialog1,CheckBox1,Checked,varLog

If>%varLog%=False
setDialogProperty>Dialog1,CheckBox2,Checked,True
MessageModal>%varLog%

else
setDialogProperty>Dialog1,CheckBox2,Checked,False
MessageModal>%varLog%

endif

END>DisEnableLogs

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

Post by JRL » Thu May 17, 2012 4:58 am

It appears the setDialogProperty>Dialog1,CheckBox2,Checked,XXX lines are causing the adddialoghandler event for checkbox2 to fire. You can verify this by remarking out that dialog handler line and you can see that picking on checkbox1 then only runs the subroutine once. I don't know if that is what I would expect to see but it appears to be what is happening.

Actually, if setdialogproperty checking the box sets off the dialoghandler, I would expect what you have written to go into an endless loop. Maybe Marcus can explain this.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu May 17, 2012 7:58 am

If you have created a handler for the checkbox, OnClick, that may be part of the problem.

It turns out that any change in the status of Checked property will trigger the OnClick routine. So, it you change the property by clicking with a mouse, pressing a space bar, or using SetProperty command, the OnClick will fire.

It has been suggested that the property "Checked" should properly be named something like "CheckStatusChanged". but Marcus is unable to change the name, the subcode Macro Scheduler uses is from another source.

Maybe using a Radio Button vs. a Checkbox might work here? They automatically toggle status of the other choice(s)
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

arobin4
Junior Coder
Posts: 33
Joined: Sat Apr 07, 2012 5:41 am

Post by arobin4 » Thu May 17, 2012 4:03 pm

Bob and JRL:
Thanks for sharing your thoughts. In the case of the checkbox "OnClick" actually refers to any change in state. So long as I understand the behavior, I can code with this knowledge in mind.


Thanks

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