MS Dialog Check Box "OnClick" Observation

General Macro Scheduler discussion

Moderators: JRL, Dorian (MJT support)

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

MS Dialog Check Box "OnClick" Observation

Post by JRL » Tue Jul 19, 2011 2:08 pm

Just discovered that changing the "Checked" property of a Macro Scheduler dialog check box programmatically, will trigger the "OnClick" event for that check box. In other words, if you create a dialog with a check box and also create a dialog handler for that check box that triggers on the "OnClick" event, when you use SetDialogProperty to alter the "Checked" property of the check box, the "OnClick" event's subroutine will be processed.

I would have thought that a check box "OnClick" would require an actual mouse click but apparently it simply requires a status change. This makes some sense since a user could also alter the state of a check box by tabbing to it and pressing the space bar.

Here is a script to demonstrate. Roughly once per second the check box will be checked or unchecked by the program. There is an adddialoghandler function for the check box's OnClick event. Each time the check box's status is changed, the OnClick event will be triggered and a message box with a counter will open. If the word "True" at the end of Line 40 is changed to "False", the check box state will no longer change and the OnClick event will not be triggered.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  object CheckBox1: TCheckBox
    Left = 50
    Top = 100
    Width = 97
    Height = 17
    Caption = 'CheckBox1'
    TabOrder = 8
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnCLose,Quit
AddDialogHandler>Dialog1,checkbox1,OnClick,Report
Let>RepCount=0

SRT>Report
  Add>RepCount,1
  Message>RepCount
END>Report

SRT>Quit
  Exit>0
END>Quit

Show>Dialog1

Let>kk=0

Label>Loop
  Wait>0.01
  Add>kk,1
  Let>test={%kk% mod 100}
  If>test=0
    GetDialogProperty>Dialog1,checkbox1,Checked,res
    If>res=True
      SetDialogProperty>Dialog1,checkbox1,Checked,False
    Else
      SetDialogProperty>Dialog1,checkbox1,Checked,True
    EndIf
  EndIf
Goto>Loop

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Jul 19, 2011 2:30 pm

Yes, as you know these objects are inherited Delphi controls, and I recently discovered this to my peril in Delphi and managed to put myself into an infinite loop :-)

Before someone says "why isn't it documented" the answer is "it isn't." I also only discovered this by accident myself and I guess it suggests that OnClick is badly named - OnChangeCheckedStatus might be more accurate and it would then be logical why this happens. We'd have to ask CodeGear.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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

Post by JRL » Tue Jul 19, 2011 2:35 pm

Before someone says "why isn't it documented" the answer is...
I thought I just documented it. :wink:

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Tue Jul 19, 2011 6:54 pm

mtettmar wrote:Before someone says "why isn't it documented" the answer is "it isn't." I also only discovered this by accident myself and I guess it suggests that OnClick is badly named - OnChangeCheckedStatus might be more accurate and it would then be logical why this happens. We'd have to ask CodeGear.
CodeGear? Don't you mean Embarcadero? Googling...

http://en.wikipedia.org/wiki/Embarcadero_Delphi

"Embarcadero Delphi, formerly CodeGear Delphi, Inprise Delphi and Borland Delphi, is an integrated development environment for Microsoft Windows applications..."

Ahh... an old name of the company. If you do ask them, please share what they say. I wonder if they would agree and rename the event?
JRL wrote:
Before someone says "why isn't it documented" the answer is...
I thought I just documented it. :wink:
By George, I think you just did... thanks for sharing... no wonder we're past 30,000 forum posts!

Take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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