IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Paradox
Search Paradox Group:

Advanced
-Collapse +Expand Paradox To/From
To/FromCODEGuides
-Collapse +Expand Paradox Store
PRESTWOODSTORE

Prestwood eMagazine

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

   ► KBDesktop Data...Paradox & Ob...ObjectPAL Co...OPAL: Commands   Print This     
  From the October 2010 Issue of Prestwood eMag
 
Paradox OPAL: Commands:
Set Your Working Directory With ObjectPAL
 
Posted 16 years ago on 5/24/2008
Take Away: Use setWorkingDir then trap for MenuChangingWork in menuAction.

KB101121

Suppose that you have code that relies on objects that are in the same directory as the form, and you want to automatically change your working directory to that directory when the form is opened. This section shows you how to accomplish this.

Demo Files: WORK1.FSL.

Step By Step

1. Change your working directory to Paradox's Samples directory and create a new form.

2. In the init method of the form, type lines 3-14. Line 4 declares f as a Form variable and dyn1 as a DynArray ready to accept string values. Line 8 is rather interesting. It uses attach() to attach f to the current form. When you attach to the current form, you do not have to include its title. Line 9 checks to see whether the current working directory is the same directory the form is in. If it is not, then line 10 uses getFilename() and splitFullFileName() to extract the form's path. Line 11 sets the working directory.

 1: ;Form :: init
 2: method init(var eventInfo Event)
 3: var
 4:  f  Form
 5:  dynDir   DynArray[] String
 6: endVar

 7: ;Set working directory to this directory.
 8: f.attach()
 9: if not isFile(":WORK:ANSWERS.FSL") then
10: splitFullFileName(f.getFileName(), dynDir)
11: if not setWorkingDir(dynDir["Drive"] + dynDir["Path"]) then
12: errorShow()
13: endIf
14: endIf
15: endMethod

3. In the menuAction event of the form, type lines 8-10. Similar to the previous example, in step 3, line 9 checks for the constant MenuChangingWork. If it is detected, line 10 sets an error code to a nonzero value.

 1: ;Form :: menuAction
 2: method menuAction(var eventInfo MenuEvent)
 3: if eventInfo.isPreFilter() then
 4: ;// This code executes for each object on the form:
 5:
 6: else
 7: ;// This code executes only for the form:
 8: if eventInfo.id() = MenuChangingWork then
 9: eventInfo.setErrorCode(1)
10: endIf
11: endIf
12: endMethod

4. Check the syntax and save the form as WORK1.FSL. Change your working directory to a different directory (such as C:\) and open the form. After the form opens, check the current working directory by selecting File | Working Directory.


Comments

0 Comments.
Share a thought or comment...
 
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 = P157A1
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 #101121 Counter
10435
Since 5/24/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]