File Browse Cancel Issue

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

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

File Browse Cancel Issue

Post by JRL » Thu Feb 18, 2016 9:02 pm

I discovered that if you have a browse button that runs an "Open" browse window that you open more than once, when you "cancel" the browse window rather than "open" another file, the previously opened file is reopened.

This can be demonstrated using the supplied "Dialogs - File Browse Example" script.
Open the script
Browse to a file and open it
Then clear the edit field that contains the file name
Browse a second time but cancel or close the browse window.
The edit field will again populate with the previously chosen file.

I struggled with this for an hour in a long script I've been working on. Finally went back to the supplied example and figured out that the Browse button property "FileName" still contains the value of the last file opened. For cancel to work properly the value needs to be set back to nothing.

I've posted the script as it is now on my computer. I'd suggest the following line be added to the Macro Scheduler samples to avoid confusion in the future:

SetDialogProperty>Dialog1,MSButton1,Filename,

Thanks,
Dick

Code: Select all

Dialog>Dialog1
object Dialog1: 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
    BitmapFile =
      'C:\Documents and Settings\Marcus\My Documents\RAD Studio\Project' +
      's\msched_work\open.bmp'
    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>Dialog1

AddDialogHandler>Dialog1,MSButton1,OnClick,DoBrowse

Show>Dialog1,r

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
  SetDialogProperty>Dialog1,MSButton1,Filename,
END>DoBrowse

User avatar
Meryl
Staff
Posts: 124
Joined: Wed Sep 19, 2012 1:53 pm
Location: Texas
Contact:

Re: File Browse Cancel Issue

Post by Meryl » Mon Feb 22, 2016 1:38 pm

Thanks for sharing that so others can learn from your experience!

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