Functioning menu and opening new dialogs

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Zjaii
Newbie
Posts: 11
Joined: Fri Oct 15, 2010 3:48 pm

Functioning menu and opening new dialogs

Post by Zjaii » Sun Oct 31, 2010 2:24 pm

So I am trying to piecemeal some begginner code together for a functional menu and I started with trying to prompt a "Load" dialog because I havent explored reading and writting to files (because I am not sure how I want to survey directories to pick a default location for config..whatever). So I speculate I am not triggering the Dialog13 properly, and Dialog13 should also trigger the file browse (which seems to work in its own right) when clicking on the icon.

What am I missing?

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

//Main Dialog1
Dialog>Dialog1
object Dialog1: TForm
  Left = 404
  Top = 162
  HelpContext = 5000
  BorderIcons = [biSystemMenu, biMinimize, biMaximize]

  Caption = 'Dialog1'
  ClientHeight = 196
  ClientWidth = 439
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesigned
  ShowHint = True
  PixelsPerInch = 96
  TextHeight = 13
  Menu = MainMenu
  object Label1: TLabel
    Left = 24
    Top = 32
    Width = 70
    Height = 13
    Caption = 'Menu Example'
  end
  object MainMenu: TMSMainMenu
    object MenuItem1: TMSMenuItem
      Caption = '&File'
      object MenuItem11: TMSMenuItem
        Caption = '&New'
      end
      object MenuItem12: TMSMenuItem
        Caption = '&Save'
      end
      object MenuItem13: TMSMenuItem
        Caption = '&Load'
      end
      object MenuItem14: TMSMenuItem
        Caption = '&Exit'
      end
    end
    object MenuItem2: TMSMenuItem
      Caption = '&Help'
      object MenuItem21: TMSMenuItem
        Caption = '&About'
      end
    end
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,DoExit
//AddDialogHandler>Dialog1,MenuItem1,OnClick,DoNothing
AddDialogHandler>Dialog1,MenuItem11,OnClick,DoNew
AddDialogHandler>Dialog1,MenuItem12,OnClick,DoSave
AddDialogHandler>Dialog1,MenuItem13,OnClick,DoLoad
AddDialogHandler>Dialog1,MenuItem14,OnClick,DoExit
//AddDialogHandler>Dialog1,MenuItem2,OnClick,DoNothing
AddDialogHandler>Dialog1,MenuItem21,OnClick,DoAbout

Show>Dialog1,r

//New Dialog11

//Save Dialog12

//Load Dialog13
Dialog>Dialog13
object Dialog13: TForm
  Left = 469
  Top = 146
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'File Browse Example'
  ClientHeight = 288
  ClientWidth = 308
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesigned
  ShowHint = True
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 16
    Top = 16
    Width = 53
    Height = 13
    Caption = 'Enter a file:'
  end
  object Edit1: TEdit
    Left = 16
    Top = 41
    Width = 248
    Height = 21
    TabOrder = 8
  end
  object MSButton1: tMSButton
    Left = 269
    Top = 41
    Width = 21
    Height = 21
    DoubleBuffered = True
    Glyph.Data = {
      F6000000424DF600000000000000760000002800000010000000100000000100
      0400000000008000000000000000000000001000000010000000000000000000
      80000080000000808000800000008000800080800000C0C0C000808080000000
      FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
      77777777777777777777000000000007777700333333333077770B0333333333
      07770FB03333333330770BFB0333333333070FBFB000000000000BFBFBFBFB07
      77770FBFBFBFBF0777770BFB0000000777777000777777770007777777777777
      7007777777770777070777777777700077777777777777777777}
    ParentDoubleBuffered = False
    TabOrder = 9
    DoBrowse = False
    Filter = 'Text files (*.txt)|*.TXT|Any file (*.*)|*.*'
    BrowseStyle = fbOpen
  end
  object MSMemo1: tMSMemo
    Left = 16
    Top = 72
    Width = 273
    Height = 161
    ScrollBars = ssBoth
    TabOrder = 10
  end
  object MSButton2: tMSButton
    Left = 215
    Top = 247
    Width = 75
    Height = 25
    Caption = 'Close'
    DoubleBuffered = True
    ModalResult = 2
    ParentDoubleBuffered = False
    TabOrder = 11
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog13

AddDialogHandler>Dialog13,MSButton1,OnClick,DoBrowse

Show>Dialog13,r

SRT>DoNew
  SetDialogProperty>Dialog1,MSButton1,DoNew,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog1,Edit1,Text,strFileName
  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog1,MSMemo1,Text,strFileData
END>DoNew

SRT>DoSave
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog1,Edit1,Text,strFileName
  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog1,MSMemo1,Text,strFileData
END>DoSave

SRT>DoLoad
  SetDialogProperty>Dialog13,MSButton1,DoLoad,True
  GetDialogProperty>Dialog13,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog13,Edit1,Text,strFileName
  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog13,MSMemo1,Text,strFileData
END>DoLoad

SRT>DoBrowse
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog1,Edit1,Text,strFileName
  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog1,MSMemo1,Text,strFileData
END>DoBrowse

SRT>DoExit
  Exit>0
END>DoExit

SRT>DoAbout
  MessageModal>Don't ask stupid questions.
END>DoAbout


Zjaii
Newbie
Posts: 11
Joined: Fri Oct 15, 2010 3:48 pm

Post by Zjaii » Mon Nov 01, 2010 2:05 am

Moving the Dialog13 info inside the DoLoad section gets it to load but selecting the load option a second time causes an error and it doesnt call the DoBrowse function appropriately.

Code: Select all

//Main Dialog1
Dialog>Dialog1
object Dialog1: TForm
  Left = 404
  Top = 162
  HelpContext = 5000
  BorderIcons = [biSystemMenu, biMinimize, biMaximize]

  Caption = 'Dialog1'
  ClientHeight = 196
  ClientWidth = 439
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesigned
  ShowHint = True
  PixelsPerInch = 96
  TextHeight = 13
  Menu = MainMenu
  object Label1: TLabel
    Left = 24
    Top = 32
    Width = 70
    Height = 13
    Caption = 'Menu Example'
  end
  object MainMenu: TMSMainMenu
    object MenuItem1: TMSMenuItem
      Caption = '&File'
      object MenuItem11: TMSMenuItem
        Caption = '&New'
      end
      object MenuItem12: TMSMenuItem
        Caption = '&Save'
      end
      object MenuItem13: TMSMenuItem
        Caption = '&Load'
      end
      object MenuItem14: TMSMenuItem
        Caption = '&Exit'
      end
    end
    object MenuItem2: TMSMenuItem
      Caption = '&Help'
      object MenuItem21: TMSMenuItem
        Caption = '&About'
      end
    end
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,DoExit
//AddDialogHandler>Dialog1,MenuItem1,OnClick,DoNothing
AddDialogHandler>Dialog1,MenuItem11,OnClick,DoNew
AddDialogHandler>Dialog1,MenuItem12,OnClick,DoSave
AddDialogHandler>Dialog1,MenuItem13,OnClick,DoLoad
AddDialogHandler>Dialog1,MenuItem14,OnClick,DoExit
//AddDialogHandler>Dialog1,MenuItem2,OnClick,DoNothing
AddDialogHandler>Dialog1,MenuItem21,OnClick,DoAbout

Show>Dialog1,r

//New Dialog11
SRT>DoNew
  SetDialogProperty>Dialog1,MSButton1,DoNew,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog1,Edit1,Text,strFileName
  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog1,MSMemo1,Text,strFileData
END>DoNew

//Save Dialog12
SRT>DoSave
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog1,Edit1,Text,strFileName
  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog1,MSMemo1,Text,strFileData
END>DoSave

//Load Dialog13
SRT>DoLoad
Dialog>Dialog13
object Dialog13: TForm
  Left = 469
  Top = 146
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'File Browse Example'
  ClientHeight = 288
  ClientWidth = 308
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesigned
  ShowHint = True
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 16
    Top = 16
    Width = 53
    Height = 13
    Caption = 'Enter a file:'
  end
  object Edit1: TEdit
    Left = 16
    Top = 41
    Width = 248
    Height = 21
    TabOrder = 8
  end
  object MSButton1: tMSButton
    Left = 269
    Top = 41
    Width = 21
    Height = 21
    DoubleBuffered = True
    Glyph.Data = {
      F6000000424DF600000000000000760000002800000010000000100000000100
      0400000000008000000000000000000000001000000010000000000000000000
      80000080000000808000800000008000800080800000C0C0C000808080000000
      FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
      77777777777777777777000000000007777700333333333077770B0333333333
      07770FB03333333330770BFB0333333333070FBFB000000000000BFBFBFBFB07
      77770FBFBFBFBF0777770BFB0000000777777000777777770007777777777777
      7007777777770777070777777777700077777777777777777777}
    ParentDoubleBuffered = False
    TabOrder = 9
    DoBrowse = False
    Filter = 'Text files (*.txt)|*.TXT|Any file (*.*)|*.*'
    BrowseStyle = fbOpen
  end
  object MSMemo1: tMSMemo
    Left = 16
    Top = 72
    Width = 273
    Height = 161
    ScrollBars = ssBoth
    TabOrder = 10
  end
  object MSButton2: tMSButton
    Left = 215
    Top = 247
    Width = 75
    Height = 25
    Caption = 'Close'
    DoubleBuffered = True
    ModalResult = 2
    ParentDoubleBuffered = False
    TabOrder = 11
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog13

  SetDialogProperty>Dialog13,MSButton1,DoLoad,True
  GetDialogProperty>Dialog13,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog13,Edit1,Text,strFileName
  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog13,MSMemo1,Text,strFileData
  
 // AddDialogHandler>Dialog13,MSButton1,OnClick,DoBrowse
Show>Dialog13,r
END>DoLoad

//Browse Dialog
SRT>DoBrowse
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog1,Edit1,Text,strFileName
  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog1,MSMemo1,Text,strFileData
END>DoBrowse

//Exit
SRT>DoExit
  Exit>0
END>DoExit

SRT>DoAbout
  MessageModal>Don't ask stupid questions.
END>DoAbout

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

Post by JRL » Mon Nov 01, 2010 2:39 am

You're on the right track. You can only call a dialog block once in a script. That's why you're getting an error the second time you call the browse dialog. But you were right to move the dialog13 Show> to the "DoLoad" subroutine.

Try this.

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

//Main Dialog1
Dialog>Dialog1
object Dialog1: TForm
  Left = 404
  Top = 162
  HelpContext = 5000
  BorderIcons = [biSystemMenu, biMinimize, biMaximize]

  Caption = 'Dialog1'
  ClientHeight = 196
  ClientWidth = 439
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesigned
  ShowHint = True
  PixelsPerInch = 96
  TextHeight = 13
  Menu = MainMenu
  object Label1: TLabel
    Left = 24
    Top = 32
    Width = 70
    Height = 13
    Caption = 'Menu Example'
  end
  object MainMenu: TMSMainMenu
    object MenuItem1: TMSMenuItem
      Caption = '&File'
      object MenuItem11: TMSMenuItem
        Caption = '&New'
      end
      object MenuItem12: TMSMenuItem
        Caption = '&Save'
      end
      object MenuItem13: TMSMenuItem
        Caption = '&Load'
      end
      object MenuItem14: TMSMenuItem
        Caption = '&Exit'
      end
    end
    object MenuItem2: TMSMenuItem
      Caption = '&Help'
      object MenuItem21: TMSMenuItem
        Caption = '&About'
      end
    end
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,DoExit
//AddDialogHandler>Dialog1,MenuItem1,OnClick,DoNothing
AddDialogHandler>Dialog1,MenuItem11,OnClick,DoNew
AddDialogHandler>Dialog1,MenuItem12,OnClick,DoSave
AddDialogHandler>Dialog1,MenuItem13,OnClick,DoLoad
AddDialogHandler>Dialog1,MenuItem14,OnClick,DoExit
//AddDialogHandler>Dialog1,MenuItem2,OnClick,DoNothing
AddDialogHandler>Dialog1,MenuItem21,OnClick,DoAbout

//Load Dialog13
Dialog>Dialog13
object Dialog13: TForm
  Left = 274
  Top = 150
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'File Browse Example'
  ClientHeight = 288
  ClientWidth = 308
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesigned
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 16
    Top = 16
    Width = 53
    Height = 13
    Caption = 'Enter a file:'
  end
  object Edit1: TEdit
    Left = 16
    Top = 41
    Width = 248
    Height = 21
    TabOrder = 0
  end
  object MSButton1: tMSButton
    Left = 269
    Top = 41
    Width = 21
    Height = 21
    DoubleBuffered = True
    Glyph.Data = {
      F6000000424DF600000000000000760000002800000010000000100000000100
      0400000000008000000000000000000000001000000010000000000000000000
      80000080000000808000800000008000800080800000C0C0C000808080000000
      FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
      77777777777777777777000000000007777700333333333077770B0333333333
      07770FB03333333330770BFB0333333333070FBFB000000000000BFBFBFBFB07
      77770FBFBFBFBF0777770BFB0000000777777000777777770007777777777777
      7007777777770777070777777777700077777777777777777777}
    ParentDoubleBuffered = False
    TabOrder = 1
    DoBrowse = False
    Filter = 'Text files (*.txt)|*.TXT|Any file (*.*)|*.*'
    BrowseStyle = fbOpen
  end
  object MSMemo1: tMSMemo
    Left = 16
    Top = 72
    Width = 273
    Height = 161
    ScrollBars = ssBoth
    TabOrder = 2
  end
  object MSButton2: tMSButton
    Left = 215
    Top = 247
    Width = 75
    Height = 25
    Caption = 'Close'
    DoubleBuffered = True
    ModalResult = 2
    ParentDoubleBuffered = False
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog13

Show>Dialog1,r

//New Dialog11

//Save Dialog12


SRT>DoNew
  SetDialogProperty>Dialog1,MSButton1,DoNew,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog1,Edit1,Text,strFileName
  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog1,MSMemo1,Text,strFileData
END>DoNew

SRT>DoSave
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog1,Edit1,Text,strFileName
  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog1,MSMemo1,Text,strFileData
END>DoSave

SRT>DoLoad
  AddDialogHandler>Dialog13,MSButton1,OnClick,DoBrowse
  Show>Dialog13,r
  SetDialogProperty>Dialog13,MSButton1,DoLoad,True
  GetDialogProperty>Dialog13,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog13,Edit1,Text,strFileName
  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog13,MSMemo1,Text,strFileData

END>DoLoad

SRT>DoBrowse
  SetDialogProperty>Dialog13,MSButton1,DoBrowse,True
  GetDialogProperty>Dialog13,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog13,Edit1,Text,strFileName
  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog13,MSMemo1,Text,strFileData
END>DoBrowse

SRT>DoExit
  Exit>0
END>DoExit

SRT>DoAbout
  MessageModal>Don't ask stupid questions.
END>DoAbout

Zjaii
Newbie
Posts: 11
Joined: Fri Oct 15, 2010 3:48 pm

Post by Zjaii » Mon Nov 01, 2010 3:25 pm

JRL? You're machine! Thanks!

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