Wednesday, May 20, 2009

Selecting a file from a QUEST library (using SCL)

QUEST SCL provides a means for an SCL programmer to call the standard file selection dialog box, where the user can pick a file from a specific folder from a specific set of libraries. This function is called FILE_POP_UP. You pass in a string or string array containing the directory (or directories) to be shown in the dialog box.

The way I use FILE_POP_UP, I use the inquire_config_path to populate a string array with all the libraries containing a specified folder name, and pass that array to FILE_POP_UP. I've encapsulated this functionality into a single SCL routine you can use:

routine get_filename( folder_name : String ) : String
Var
cpaths : array [50] of String
numpths : Integer
result : String
Begin
inquire_config_path( folder_name + '$LIB',cpaths, numpths)
FILE_POP_UP(cpaths, result)
return result
End

Now rather than havign to remember how to use inquire_config_path along with FILE_POP_UP, I can simply call a routine like so:

sel_file_path = get_filename( 'DATA' )

And of course, when you want the user to be able to select an SCL logic file, you'll want to be able to provide the option of selecting from the LOGICS and SCLMACROS folders from your libraries, so I've created a routine that takes two folder names, and combines their inquire_config_path results into a single array that gets passed to the FILE_POP_UP. Here it is:

routine get_filename_multiple( folder_name1 : String ; folder_name2 : String ) : String
Var
cpaths , cpaths2 : array [50] of String
the_paths : Array[ 100 ] of String
numpths , numpths2 , i , write_idx : Integer
result : String
Begin

inquire_config_path( folder_name1 + '$LIB',cpaths, numpths)
inquire_config_path( folder_name2 + '$LIB',cpaths2, numpths2)
write_idx = 0
for i = 0 to numpths - 1 do
if( cpaths[ i ] <> '' ) then
the_paths[ write_idx ] = cpaths[ write_idx ]
write_idx = write_idx + 1
endif
endfor
for i = 0 to numpths2 - 1 do
if( cpaths2[ i ] <> '' ) then
the_paths[ write_idx ] = cpaths2[ i ]
write_idx = write_idx + 1
endif
endfor
FILE_POP_UP(the_paths, result)
return result

End

You can use it like so:

sel_file_path = get_filename_multiple( 'LOGIC' , 'SCLMACRO' )


No comments: