I.T. Discussion Community!
-Collapse +Expand
Search Paradox Group:

-Collapse +Expand Paradox To/From
-Collapse +Expand Paradox Store

Prestwood eMagazine

February Edition
Subscribe now! It's Free!
Enter your email:

   ► KBDesktop Data...Paradox & Ob...ObjectPAL Co...OPAL: Commands   Print This     
  From the August 2010 Issue of Prestwood eMag
Paradox OPAL: Commands:
Finding and Listing a Set of Files
Posted 11 years ago on 6/3/2008
Take Away: ObjectPAL example that demonstrates listing a set of files and allowing the user to launch any one of them by double clicking.


Suppose that you want to create a form that lists all the files in a directory and enables the user to launch a file by double-clicking its filename. This next step by step example uses the FileSystem methods to search your Windows directory for .EXE files and puts them in a list field. When the user double clicks on a filename, the .EXE file is launched.


Step By Step

1. Create a new form with two undefined fields. Label the first undefined field Search For, and change its name to SearchForField.

Set up form


2. Make the second undefined field a list field; change its name to fldResult and its list to FileList. Figure 4 shows the Object Tree of the list field. The list object is inside the field object.

The Object Tree of the list field


3. Place a text object above the fldResult field with the text Double click to execute.

4. Add line 3 to the Var window of the Search for field.

1: ;SearchForField :: Var
2: Var
3: fs FileSystem
4: endVar

5. Add lines 3 and 4 to the open event of the Search for field.

1: ;SearchForField :: open
2: method open(var eventInfo Event)
3: doDefault
4: self.value = windowsDir() + "\\*.EXE"
5: endMethod

6. Add lines 3--17 to the newValue event of the Search for field.

 1: ;SearchForField :: newValue
 2: method newValue(var eventInfo Event)
 3: if not SearchForField.isBlank() then
 4:   if fs.findFirst(SearchForField) then
 5: fldResult.FileList.list.count = 0
 6: fldResult.FileList.list.selection = 1
 7: fldResult.FileList.list.value = FS.name()
 8: while FS.findNext()
 9:   fldResult.FileList.list.selection = fldResult.FileList.list.selection +1
10:  fldResult.FileList.list.value = FS.name()
11:  endWhile
12:  else
13:  fldResult.FileList.list.count = 0
14:  fldResult.FileList.list.selection = 1
15:  fldResult.FileList.list.value = "File not found"
16:  endIf
17: endIf
18: endMethod

7. Add lines 3--7 to the mouseDouble event of the fldResult field.

1: ;fldResult :: mouseDouble
2: method mouseDouble(var eventInfo MouseEvent)
3: try
4:   execute(fldResult.value)
5: onFail
6:   msgStop("Warning", "Could not launch file")
7: endTry
8: endMethod

Check the syntax and save the form. Run the form. All the .EXE files from your Windows directory are listed. If you double-click a file, it will execute. Change the extension to .HLP. If .HLP is associated with WINHELP.EXE like the Windows default, you can double-click any Help file to launch it. Now, type in an invalid extension, such as .XYZ. The words File not found appear.

In step 3, line 3 sets up fs as a FileSystem variable. It's used later in step 5.

In step 4, line 4 populates the Search for field after invoking the default behavior.

In step 5, line 3 checks the value, and line 9 uses it and the fs System variable to find the first occurrence of the search criteria. If nothing is found, the execution skips to line 14. Lines 14--16 clear the list and set the first value to File not found. If line 3 finds a file, lines 5--7 clear the list and set the initial value, and lines 8--12 loop through and populate the rest of the list.

In step 6, lines 3--7 attempt to launch the value that you double-click. These lines use a try block. If you don't use a try block, ObjectPAL will display abstract errors when the file isn't found. In other words, many ObjectPAL errors are meant for the programmer. You might want to use a try structure to test your code. If it fails, display a more meaningful message to the end user.


Share a thought or comment...
Comment 1 of 1

Hi Mike

This works fine, but if I change *.EXE to *.PDF, I get a list of PDF-files allright, but it fails by doubleclick - Could not launch file. Have tried with execute("explorer fldResult.value"), but that only opens the explorer, and not the pdf-file in a pdf-reader. I have also tried to change from windowsdir () to a defined alias - self.value = :myalias: + \\*.EXE. That works fine with the list, but not the execute.

Any idea why this doesn't work ?


Posted 7 years ago
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1182A1
Enter key:
KB Post Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101148 Counter
Since 6/3/2008
   Contact Us!
PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

2,193 People Online Now!!  
Sign In to see who's online now!  Not a member? Join now. It's free!
Show more stats...

©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech