Exit Dialog from Dialog Handler

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Exit Dialog from Dialog Handler

Post by kpassaur » Fri Jun 04, 2010 11:54 am

What I am trying to do is rather simple. When a user clicks on a button it sees if a program is running if it is the user can shut it down. If not is starts and the current script ends.

With version 11 I just reset the dialog action to "2" to exit as was shown in the help file.

With version 12 that does not seem to work so I did what you are not supposed to do and just put an "Exit>0" line in the subroutine. Which works when you step through it, but not when you compile it.

What is the propper way to do it now.

Here is what I am using:

SRT>Runit
GetDialogProperty>Dialog1,MSBUTTON1,Caption,btext
If>%btext%=Run Program
Let>RP_WAIT=0
ChangeDirectory>%ProgramFolder%
RunProgram>File_One_Processing.exe
Exit>0
Else
VBRun>KillProcess,File_One_Processing.exe
SetDialogProperty>Dialog1,MSBUTTON1,Caption,Run Program
Endif
End>Runit

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

Post by Marcus Tettmar » Fri Jun 04, 2010 12:31 pm

Exit should be working outside of debug. I'll get that looked at.

However .....

If it's a modal dialog then just give the button a ModalResult value to make it close the dialog when clicked.

In v12 if it's a modal dialog and you don't want the button to close it then leave the button's modalresult to 0 and then simply call CloseDialog in the buttons click handler. This will close the dialog with a modal result of 2:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 390
  Top = 182
  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 MSButton1: tMSButton
    Left = 179
    Top = 73
    Width = 75
    Height = 25
    Caption = 'MSButton1'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 8
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,msButton1,OnClick,DoClick

Show>Dialog1,r

SRT>DoClick
  //do what you need here and if required ...
  CloseDialog>Dialog1
END>DoClick
In v12 you should very rarely need a non-modal dialog. But if you do want a non-modal dialog you could do something like this:

Code: Select all

AddDialogHandler>Dialog1,msButton1,OnClick,DoClick

Show>Dialog1

Label>someloop
Wait>0.2

If>endit<>true
  Goto>someloop
Endif

SRT>DoClick
  //do what you need here and if required ...
  CloseDialog>Dialog1
  Let>endit=true
END>DoClick
So the click closes the dialog, sents endit to true, which causes the main loop to terminate.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Dialogs

Post by kpassaur » Sun Jun 06, 2010 11:39 am

This is what I am finding confusing on version 12.

I would just as well always use a DialogHandler to access dialog functions. However, (and perhaps this is just me) it does not allow it to go to a label only a subroutine. But when you run it the error message says cannot find subroutine/label. The label is present.

Making it go to a label to me makes sense, you go to the label, close the dialog and continue. If you need it again you show it. To make it so that everything is always in a subroutine makes it very confusing if you have multiple dialogs. Again this is just me. I have found with the Dialoghandler updating dialogs is extremly easy now. I have a button that says test, a subroutine is executed, results are easy placed in the Dialog. The only difficuly is in when you want to exit it the dialog and continue. If you exit out is continues the script, so you seem to always have to put in a modal result of 2.

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

Post by Marcus Tettmar » Mon Jun 07, 2010 8:59 am

We've fixed using Exit inside a dialog handler subroutine in dev. Hope to have an update today/asap.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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