Wait on Click in Ver 12 Dialog

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

Wait on Click in Ver 12 Dialog

Post by kpassaur » Wed Jun 30, 2010 9:02 am

I have a dialog in Ver 12 with a list. The user can select an item on the list and press a button to move it up or down. This works fine most of the time. However with a long list on occasion it fails and the only thing I can think of is that the subroutine has not finished processing before the user clicks again.

Is there anyway to deactivate a button's click function and then reactivate it. So the user clicks, the button is deactivated at the begininig of the subroutine and the last line reactivates the button.

Below is the subroutine for moving up (down is similar) if someone would like to use it.

Code: Select all

SRT>Move_Up

GetDialogProperty>RulesDialog,ruleslistbx,SelectedIndex,rn
Let>x=%rn%
If>%rn%=-1
MDL>No Rule is selected
Goto>end_of_up_sub
Endif

Endif
If>%rn%=0
MDL>This is the First Rule it cannot be moved up
Goto>end_of_up_sub
Endif
Let>rn=%rn%+1
  ReadLn>%settinsdir%\%jname%.csv,rn,Line
  ReadFile>%settinsdir%\%jname%.csv,rlist
  StringReplace>%rlist%,%Line%%CRLF%,,nline
  DeleteFile>%settinsdir%\temp.tmp
  Let>WLN_NOCRLF=1
  WriteLn>%settinsdir%\temp.tmp,result,nline
  Let>WLN_NOCRLF=0
  DeleteFile>%settinsdir%\%jname%.csv
  Let>u=1
  Label>start_move_up
  ReadLn>%settinsdir%\temp.tmp,%u%,uline
  If>uline=##EOF##,done_with_up
  If>%u%=%x%
  WriteLn>%settinsdir%\%jname%.csv,result,%Line%
  WriteLn>%settinsdir%\%jname%.csv,result,%uline%
  Else
  WriteLn>%settinsdir%\%jname%.csv,result,%uline%
  Endif
  Let>u=u+1
  Goto>start_move_up
   
  
  Label>done_with_up
  ReadFile>%settinsdir%\%jname%.csv,rlist
  SetDialogProperty>RulesDialog,ruleslistbx,Text,%rlist%
  Let>x=%x%-1
  SetDialogProperty>RulesDialog,ruleslistbx,SelectedIndex,%x%
  Label>end_of_up_sub
  
END>Move_Up

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

Post by JRL » Wed Jun 30, 2010 1:48 pm

Is there anyway to deactivate a button's click function and then reactivate it. So the user clicks, the button is deactivated at the begininig of the subroutine and the last line reactivates the button.
Use two buttons at the exact same location. At the beginning of the script, the primary button is visible and the secondary button is made invisible. The second button is benign because you do not set an action for it to perform. At the start of the subroutine, make the primary button invisible and make the secondary button visible. At the end of the subroutine make the primary button visible and the secondary button invisible.

Here's an example. The buttons are also renamed in this for clarity. You probably want to use the same name (caption) for both in your script.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 663
  Top = 187
  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 = 170
    Top = 137
    Width = 75
    Height = 25
    Caption = 'Run'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 8
    DoBrowse = False
    BrowseStyle = fbOpen
  end
    object MSButton2: tMSButton
    Left = 170
    Top = 137
    Width = 75
    Height = 25
    Caption = 'Do Not Run'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 8
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

//No dialog handler for button 2
AddDialogHandler>Dialog1,msbutton1,OnClick,Active

//Make button 2 invisible
SetDialogObjectVisible>Dialog1,msbutton2,0

Show>dialog1,res1

SRT>Active
  //make button 1 invisible and button 2 visible
  SetDialogObjectVisible>Dialog1,msbutton1,0
  SetDialogObjectVisible>Dialog1,msbutton2,1

  Let>rp_wait=1
  Run>cmd /c dir c:\ /s

  //<ake button 1 visible and button 2 invisible
  SetDialogObjectVisible>Dialog1,msbutton1,1
  SetDialogObjectVisible>Dialog1,msbutton2,0
END>Active

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

On button click

Post by kpassaur » Wed Jun 30, 2010 2:06 pm

Thanks

I ended up using

SetDialogProperty>RulesDialog,downbtn,Enabled,False

at the begining of the subroutine and

SetDialogProperty>RulesDialog,downbtn,Enabled,True

at the end and it seems to be working fine.

There are so many options with ver 12 that once I get to know then it will be great

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

Post by JRL » Wed Jun 30, 2010 2:31 pm

Wow!

Enabled = True or Enabled = False. Nice find Keith.
The new dialog format is an adventure. I like adventure. :D
  • object MSButton1: tMSButton
    Left = 170
    Top = 137
    Width = 75
    Height = 25
    Caption = 'Down'
    DoubleBuffered = True
    Enabled = False
    ParentDoubleBuffered = False
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
    end

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