It's easy to enter the wrong path or filename. To lessen the chance of error, call the Open Dialog box from Windows using the Utility("CHOOSEFILE") function, allowing the user to point and click the desired file. The path and the filename will be returned and automatically put in the picture field that holds the path and filename information.

Doing it this way will also give us the option to make the field invisible, because the path doesn't matter, only the picture.

Below is the form with a sample record:

 

Code this by following these steps:

  1. Add a button (call it BUTTON_CHOOSE) to the form.  

  2. In its Click event, code the following:

declare function utility
 
CFOpt    = ''
CFOpt<1> = 0   ;* call Open dialog
CFopt<2> = 'Images(*.jpg)/*.jpg/All Files(*.*)/*.*/'
getImageFile = Utility('CHOOSEFILE', @window , CFOpt)
 
if (getImageFile) then
  retval = Set_Property(@window : '.PICTURE','TEXT', getImageFile)
end

This code calls the Utility("CHOOSEFILE") function  to look for .jpg files in the default directory. If the user chooses a file, its path is set in the PICTURE control, which fires the Change event code illustrated in the previous topic.

  • No labels