What is Source Aliasing?

Source Aliasing is a feature in dBASE Plus that provides true source-code portability by referencing files indirectly - through an Alias. Just as the BDE allows you to define an Alias to represent a database or a collection of tables, Source Aliases let you define locations for your various files without using explicit paths - which often differ from machine to machine.

For example, if you're using seeker.cc in a dBASE Plus application, you're likely to have code similar to the following:

set procedure to "c:\program files\dBASE\Plus\Samples

\seeker.cc" additive

If you run this code on another machine, whose application drive is not "c:", it will crash.

You can avoid portability problems like the example above (as well as save a lot of typing) by using a Source Alias in place of explicit paths:

set procedure to :MainLib:seeker.cc additive

Whenever dBASE Plus sees ":MainLib:", it automatically substitutes the path assigned to this Alias. To run the same code on another computer or drive, simply set up the "MainLib" Alias to point to the appropriate folder at the new location. No source code changes are required.

There are other major benefits to Source Aliasing.

You can run applications from within dBASE Plus regardless of their location and current folder. Every application always finds all of its parts. dQuery is written using Source Aliases entirely, which is why you can run it from any directory without fear of a "File Does Not Exist" error.

You can build well-organized, reliable libraries of object source that can be accessed across many projects without dealing with complicated and changing paths. You may, for example, want to:

Build a MAIN alias that represents a folder in which you store globally shared classes.

Use an IMAGES alias to point to a location containing all your reusable bitmaps, .gifs and .jpgs.

Build a PROJECT1 alias for classes and code associated only with one specific project.

If you're careful to always use Source Aliases, your libraries will be shared with ease, and portable enough to be shared across a network by other developers and users.

Using Source Aliases

To create a new Source Alias, go to Properties|Desktop Properties menu option and click on the "Source Aliases" tab. dBASE Plus can support an unlimited number of Source Aliases.

There are at least three ways to use Source Aliases in dBASE Plus and dQuery.

  1. When hand-coding, always use an alias preceded and followed by a colon:

    set procedure to :dQuery:my.wfm additive

dataSource := "FILENAME :dQuery:NewButton.bmp" 

upBitMap := ":dQuery:OKButton.bmp" 

do :dQuery:Main.prg     

  1. When setting properties (such as Bitmaps) in the Inspector, always add the Source Alias to a filename.

  2. dBASE Plus may add Source-Aliases automatically. In many cases, dBASE Plus will substitute the correct Source Alias whenever you select a file from an Open File dialog, drag-and-drop a file from the Navigator, or type in an explicit path.

Source Alias information is stored in the PLUS.ini file. As a result, you need to add the Source Alias to any dBASE Plus installation that will run your code. You can add Aliases programmatically by modifying the PLUS.ini file.

You can retrieve the paths associated with Source Aliases through the sourceAliases property of the main application object. For example:

  ? _app.sourceAliases["dQuery"]

   returns

  c:\program files\dBASE\Plus\dQuery

Be careful! _app.sourceAliases is an Associative Array and is, therefore, case-sensitive. Capitalization must match the Alias name you set up in Desktop Properties.

Important Note: Source Aliasing works only in the dBASE Plus design environment or when running programs from within the dBASE Plus shell. It is not a runtime feature. To access files indirectly in deployed applications, use DEO (Dynamic External Objects) instead of Source Aliasing.