Dialog Changing Limited to 21 Times

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Dialog Changing Limited to 21 Times

Post by winstein » Thu Nov 07, 2013 9:53 am

I encountered this error when I attempted to shift between dialog windows through closing one and then opening the other (or closing one and then opening the same one). Basically, after changing dialog boxes 21 times, the buttons won't work anymore (even ones that are involved in the same window).

It seems to extend to other events too, because the Checkbox with the event didn't work after 21 times of dialog-changing.

What is the problem?

Code below, if you want to try it.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 531
  Top = 197
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Dialog 1'
  ClientHeight = 153
  ClientWidth = 169
  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 Label1: TLabel
    Left = 48
    Top = 112
    Width = 76
    Height = 13
    Caption = 'Times Shifted: 0'
  end
  object MSButton1: tMSButton
    Left = 35
    Top = 28
    Width = 102
    Height = 25
    Caption = 'Go To Dialog 2'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 35
    Top = 72
    Width = 102
    Height = 25
    Caption = 'Refresh Dialog 1'
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object CheckBox1: TCheckBox
    Left = 34
    Top = 141
    Width = 97
    Height = 17
    Caption = 'CheckBox1'
    TabOrder = 10
  end
end
EndDialog>Dialog1

Dialog>Dialog2
object Dialog2: TForm
  Left = 531
  Top = 197
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Dialog 2'
  ClientHeight = 88
  ClientWidth = 161
  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 Label1: TLabel
    Left = 40
    Top = 64
    Width = 76
    Height = 13
    Caption = 'Times Shifted: 0'
  end
  object MSButton1: tMSButton
    Left = 28
    Top = 22
    Width = 109
    Height = 25
    Caption = 'Go to Dialog 1'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog2

Let>WinShift=0
AddDialogHandler>Dialog1,MSButton1,OnClick,fromDialog1ToDialog2
AddDialogHandler>Dialog1,MSButton2,OnClick,fromDialog1ToDialog1
AddDialogHandler>Dialog1,CheckBox1,OnClick,MessageModalOpen
AddDialogHandler>Dialog2,MSButton1,OnClick,fromDialog2ToDialog1
Show>Dialog2,

SRT>fromDialog1ToDialog1
    CloseDialog>Dialog1
    Add>WinShift,1
    Let>Message=Times Shifted: %WinShift%
    SetDialogProperty>Dialog1,Label1,Caption,Message
    Show>Dialog1,
END>fromDialog1ToDialog1

SRT>MessageModalOpen
    MessageModal>Checked!
END>MessageModalOpen

SRT>fromDialog1ToDialog2
    CloseDialog>Dialog1
    Add>WinShift,1
    Let>Message=Times Shifted: %WinShift%
    SetDialogProperty>Dialog2,Label1,Caption,Message
    Show>Dialog2,
END>fromDialog1ToDialog2

SRT>fromDialog2ToDialog1
    CloseDialog>Dialog2
    Add>WinShift,1
    Let>Message=Times Shifted: %WinShift%
    SetDialogProperty>Dialog1,Label1,Caption,Message
    Show>Dialog1,
END>fromDialog2ToDialog1
Thanks for reading.
PPQ

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

Post by JRL » Thu Nov 07, 2013 2:56 pm

My explanation would be that you're stacking modal dialogs. I can't explain why there's a limit but there seems to be one.

Convert the modal dialogs to non-modal dialogs and the problem goes away.

The script below is your script with an added loop so the script will idle also removed the commas from all of your Show>Dialog lines. The other needed addition is a button to kill the script.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 531
  Top = 197
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Dialog 1'
  ClientHeight = 153
  ClientWidth = 169
  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 Label1: TLabel
    Left = 48
    Top = 112
    Width = 76
    Height = 13
    Caption = 'Times Shifted: 0'
  end
  object MSButton1: tMSButton
    Left = 35
    Top = 28
    Width = 102
    Height = 25
    Caption = 'Go To Dialog 2'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 35
    Top = 72
    Width = 102
    Height = 25
    Caption = 'Refresh Dialog 1'
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object CheckBox1: TCheckBox
    Left = 34
    Top = 141
    Width = 97
    Height = 17
    Caption = 'CheckBox1'
    TabOrder = 10
  end
end
EndDialog>Dialog1

Dialog>Dialog2
object Dialog2: TForm
  Left = 531
  Top = 197
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Dialog 2'
  ClientHeight = 88
  ClientWidth = 161
  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 Label1: TLabel
    Left = 40
    Top = 64
    Width = 76
    Height = 13
    Caption = 'Times Shifted: 0'
  end
  object MSButton1: tMSButton
    Left = 28
    Top = 22
    Width = 109
    Height = 25
    Caption = 'Go to Dialog 1'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog2

Let>WinShift=0
AddDialogHandler>Dialog1,MSButton1,OnClick,fromDialog1ToDialog2
AddDialogHandler>Dialog1,MSButton2,OnClick,fromDialog1ToDialog1
AddDialogHandler>Dialog1,CheckBox1,OnClick,MessageModalOpen
AddDialogHandler>Dialog2,MSButton1,OnClick,fromDialog2ToDialog1
Show>Dialog2

Label>Loop
Wait>0.01
Goto>Loop

SRT>fromDialog1ToDialog1
    CloseDialog>Dialog1
    Add>WinShift,1
    Let>Message=Times Shifted: %WinShift%
    SetDialogProperty>Dialog1,Label1,Caption,Message
    Show>Dialog1
END>fromDialog1ToDialog1

SRT>MessageModalOpen
    MessageModal>Checked!
END>MessageModalOpen

SRT>fromDialog1ToDialog2
    CloseDialog>Dialog1
    Add>WinShift,1
    Let>Message=Times Shifted: %WinShift%
    SetDialogProperty>Dialog2,Label1,Caption,Message
    Show>Dialog2
END>fromDialog1ToDialog2

SRT>fromDialog2ToDialog1
    CloseDialog>Dialog2
    Add>WinShift,1
    Let>Message=Times Shifted: %WinShift%
    SetDialogProperty>Dialog1,Label1,Caption,Message
    Show>Dialog1
END>fromDialog2ToDialog1

winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Post by winstein » Fri Nov 08, 2013 1:56 am

JRL wrote:My explanation would be that you're stacking modal dialogs. I can't explain why there's a limit but there seems to be one.

Convert the modal dialogs to non-modal dialogs and the problem goes away.

The script below is your script with an added loop so the script will idle also removed the commas from all of your Show>Dialog lines. The other needed addition is a button to kill the script.
I tried your script and, yes, every button seems to work fine now. The only problem is that closing the program will not end the process entirely, since the loop is always running (which requires manual stop to stop it).

I do find it strange that closing dialogs won't fully make them gone, though.
PPQ

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

Post by JRL » Fri Nov 08, 2013 3:38 am

winstein wrote:The only problem is that closing the program will not end the process entirely, since the loop is always running (which requires manual stop to stop it).
As I said:
The other needed addition is a button to kill the script.
winstein wrote:I do find it strange that closing dialogs won't fully make them gone, though.
From the moment a script is running and a dialog block is processed the dialog exists as a window. All we do with it is move it, resize it, modify its contents and modify its state. The dialog isn't gone until the script is exited.

winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Post by winstein » Fri Nov 08, 2013 4:08 am

JRL wrote:
winstein wrote:The only problem is that closing the program will not end the process entirely, since the loop is always running (which requires manual stop to stop it).
As I said:
The other needed addition is a button to kill the script.
What function or property is required to tell the program that I closed the program directly (as in, the red "X" button)?
PPQ

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

Post by JRL » Fri Nov 08, 2013 5:09 am

I'd make a button with the caption of "Close" or "Exit" or something similar, then have an AddDialogHandler> line that calls a "Quit" subroutine when the button is clicked.

Code: Select all

AddDialogHandler>DialogX,MSButtonX,OnClick,Quit

SRT>Quit
  Exit>0
EMD>Quit

winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Post by winstein » Fri Nov 08, 2013 6:57 am

JRL wrote:I'd make a button with the caption of "Close" or "Exit" or something similar, then have an AddDialogHandler> line that calls a "Quit" subroutine when the button is clicked.

Code: Select all

AddDialogHandler>DialogX,MSButtonX,OnClick,Quit

SRT>Quit
  Exit>0
EMD>Quit
I get that you can create a button that specifically close the program, but do you know how to terminate the program if you close by using the "X" button on the top-right portion of the window. When I did that, the loop is still running (it requires manual termination to stop it).

Maybe there could also be an option to disable the "X" button in the dialog window?
PPQ

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Fri Nov 08, 2013 10:27 am

Code: Select all

AddDialogHandler>DialogX,,OnClose,Quit

SRT>Quit
  Exit>0
EMD>Quit
Will terminate the program.

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

Post by JRL » Fri Nov 08, 2013 2:10 pm

Rain is correct. Generally that is what I would do. But in the case of this particular script and how it is written that isn't an option since every dialog swap closes the dialog, the first cycle of swapping would exit the script.

What you might try instead of closing the dialogs would be to move them to an off screen position. If you're moving them rather than closing them, the code provided by Rain will work splendidly.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 531
  Top = 197
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Dialog 1'
  ClientHeight = 153
  ClientWidth = 169
  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 Label1: TLabel
    Left = 48
    Top = 112
    Width = 76
    Height = 13
    Caption = 'Times Shifted: 0'
  end
  object MSButton1: tMSButton
    Left = 35
    Top = 28
    Width = 102
    Height = 25
    Caption = 'Go To Dialog 2'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 35
    Top = 72
    Width = 102
    Height = 25
    Caption = 'Refresh Dialog 1'
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object CheckBox1: TCheckBox
    Left = 34
    Top = 141
    Width = 97
    Height = 17
    Caption = 'CheckBox1'
    TabOrder = 10
  end
end
EndDialog>Dialog1

Dialog>Dialog2
object Dialog2: TForm
  Left = 531
  Top = 197
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Dialog 2'
  ClientHeight = 88
  ClientWidth = 161
  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 Label1: TLabel
    Left = 40
    Top = 64
    Width = 76
    Height = 13
    Caption = 'Times Shifted: 0'
  end
  object MSButton1: tMSButton
    Left = 28
    Top = 22
    Width = 109
    Height = 25
    Caption = 'Go to Dialog 1'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog2

Let>WinShift=0
AddDialogHandler>Dialog1,,OnClose,Quit
AddDialogHandler>Dialog2,,OnClose,Quit

AddDialogHandler>Dialog1,MSButton1,OnClick,fromDialog1ToDialog2
AddDialogHandler>Dialog1,MSButton2,OnClick,fromDialog1ToDialog1
AddDialogHandler>Dialog1,CheckBox1,OnClick,MessageModalOpen
AddDialogHandler>Dialog2,MSButton1,OnClick,fromDialog2ToDialog1
Show>Dialog2

    Let>WIN_USEHANDLE=1
    GetWindowPos>Dialog1.handle,Dlog1X,Dlog1Y
    MoveWindow>Dialog1.handle,-32000,-32000
    Show>Dialog1
    Let>WIN_USEHANDLE=0
Label>Loop
Wait>0.01
Goto>Loop

SRT>fromDialog1ToDialog1
    Let>WIN_USEHANDLE=1
    GetWindowPos>Dialog1.handle,Dlog1X,Dlog1Y
    MoveWindow>Dialog1.handle,-32000,-32000
    Add>WinShift,1
    Let>Message=Times Shifted: %WinShift%
    SetDialogProperty>Dialog1,Label1,Caption,Message
    MoveWindow>Dialog1.handle,Dlog1X,Dlog1Y
    Let>WIN_USEHANDLE=1
END>fromDialog1ToDialog1

SRT>MessageModalOpen
    MessageModal>Checked!
END>MessageModalOpen

SRT>fromDialog1ToDialog2
    Let>WIN_USEHANDLE=1
    GetWindowPos>Dialog1.handle,Dlog1X,Dlog1Y
    MoveWindow>Dialog1.handle,-32000,-32000
    Add>WinShift,1
    Let>Message=Times Shifted: %WinShift%
    SetDialogProperty>Dialog2,Label1,Caption,Message
    MoveWindow>Dialog2.handle,Dlog2X,Dlog2Y
    Let>WIN_USEHANDLE=1
END>fromDialog1ToDialog2

SRT>fromDialog2ToDialog1
    Let>WIN_USEHANDLE=1
    GetWindowPos>Dialog2.handle,Dlog2X,Dlog2Y
    MoveWindow>Dialog2.handle,-32000,-32000
    Add>WinShift,1
    Let>Message=Times Shifted: %WinShift%
    SetDialogProperty>Dialog1,Label1,Caption,Message
    MoveWindow>Dialog1.handle,Dlog1X,Dlog1Y
    Let>WIN_USEHANDLE=1
END>fromDialog2ToDialog1


SRT>Quit
  Exit>0
END>Quit

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Fri Nov 08, 2013 6:19 pm

You can also set the dialog properties to invisible instead of moving them off screen...then simply use Show>DialogX to make them visible again.

Code: Select all

SetDialogProperty>Dialog1,,Visible,False

SetDialogProperty>Dialog2,,Visible,False

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

Post by JRL » Fri Nov 08, 2013 8:05 pm

@Rain,

Good point, and less code. The move thing is something I used to do all the time and it just occurred to me to do it that way this a.m. Don't know why because I make extensive use of the "visible" property these days.

winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Post by winstein » Mon Nov 11, 2013 3:26 am

Took what you suggested and tried them. It seems to be fine with what I wanted to do.

Thank you all for your help!
PPQ

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