dBASE Plus — Novice Notes
The BDE alias — An introduction
by Steve Hawkins, SeHawk Services — October 29, 2002

| Introduction Definitions What is the BDE? What is an Alias? Creating an Alias Why use an Alias?

Introduction

You are about to fall into a trap! Well, sort of. If you don’t use BDE aliases when building your dBASE applications, you are destined for some headaches. If you ever want to be able to move a program’s tables around (and you likely will), use a BDE alias. The goal of this article is to provide for a basic understanding of what an alias is, how an alias can be created and why it should usually be used.

Note of caution: In your travels through the Land of dBASE, you may hear reference to the term “Source Alias”. The Source Alias is a very useful dBASE feature, but is a separate topic and has nothing to do with the BDE alias.
Definitions

- BDE stands for Borland Database Engine. The BDE is software that was created, and is owned by, Borland, Inc which licenses it to dataBased Intelligence, Inc. and many other companies.
- Alias is just what it sounds like… a different name for the same entity. A BDE alias is defined and controlled by the BDE software. When using local (“.DBF”) tables, a BDE alias points at a particular folder. You tell the BDE the name (alias) of your database folder and where that folder is located.
- Database is a term that is used many different ways by different people. In this article, it is used to describe a set of native dBASE (“.DBF”) tables that all reside in the same folder/directory.

What is the BDE?

The database engine is to dBASE what an engine is to a car; it makes data go. dBASE has no built-in means of reading or writing data to tables. Instead, dBASE communicates with the BDE and uses what the BDE feeds to it. Essentially, dBASE says to the BDE, “Hey, go get this record and show it to me.” If you want your dBASE program to work with any data tables (including .DBF files), you need the BDE. It is also the BDE software that allows you to create and define Aliases.

Of course, the BDE does many other things. It creates and maintains index files, allows for record locking and unlocking, and allows you to create tables (.DBF files). It will also allow you to work with data in other formats such as Microsoft Access’ .MDB files, but that’s for another article. I’ll focus on using .DBF files. (Author’s note: It is rumored that dataBased Intelligence, Inc. will develop their own data engine to eliminate dependency on the BDE — but still allow you to use the BDE if you wish. This is a massive undertaking though, so it probably won’t happen tomorrow.)
What is a BDE Alias?

As stated above, an alias is just a different name to describe the same thing. When using local (“.DBF”) tables, in the BDE an alias is a name that references the folder that contains a related group of .DBF tables and indexes. This group of files can in turn be referred to as a database.

Let’s say I have a collection of tables related to keeping track of my video tape collection. My video database resides in the `C:\MyFiles\MyVideo folder`. The tables include:

- Ratings.dbf (Movie Ratings... PG, PG13, R, etc)
- Video.dbf (Main file for info on each video)
- Category.dbf (Categories or "genre" for each video)

If I double-click on one of the tables in the dBASE Navigator, the BDE will open the table. I don’t need an alias just to open a table. I can also use the command window to type use `C:\MyFiles\MyVideo\Ratings.dbf` and the BDE will open the `Ratings` table without a problem.

Alternatively, I can set up an alias to “point” to the folder that contains the table. I use the BDE Administrator program and create a new alias called `Video` (demonstrated below). One of the settings for my `Video` alias indicates which folder the database currently resides in. In this case, I tell the BDE that the `Video` database is located at `C:\MyFiles\MyVideo`.

Now that an alias has been established, I no longer have to use a path statement to open the files. Instead, if I want to open the table I used previously, in the command window I can type `use :video:ratings.dbf`. To use VIDEO.DBF I would type `use :video:video.dbf`. Note the colons around the alias name of `video`. These are delimiters to indicate to dBASE that `video` is an alias name rather than part of the table name. With `use :video:ratings.dbf`, dBASE tells the BDE to “Hey, go get the `Ratings.dbf` file in the `video` database (wherever that is), and open it for me.”

By using the alias name, the BDE knows where to find the tables I want to open. Neither you nor dBASE really need to know what folder the table is in, as long as the BDE does. I can work in any folder/directory and still use the tables in my `video` folder without a problem.
Creating an alias

To create an alias, you need to use the BDE Administrator which should be installed on your computer along with dBASE. When using this program, it is best to have already closed dBASE to avoid any conflicts. You should find the shortcut / startup icon on your computer’s Control Panel.

If by chance you don’t have an icon for the BDE Administrator, search your computer for a file called `BDEAdmin.exe` and run it.

When you start the Administrator, you get a screen that is similar to the image below.

To create a new alias:

- Select the Databases tab to view currently defined aliases. Assuming yours isn’t there…
- Click the Object menu and select New
- When prompted to select a New Database Driver Name, select STANDARD

- In the tree list on the left side of the screen, name your alias (`Video` in my case)

- With your newly named alias selected, move to the DEFAULT DRIVER line on the right and select DBASE (assuming that is what you want your tables to be.)

- Leave Enable BCD at `false` and skip to the PATH line. Type in the path to your alias’ folder or use the browse button to locate it. In my case, I entered `C:\MyFiles\MyVideo`.

- Now exit the BDE Administrator and, when it asks if you want to save the changes to `IDAPI.cfg`, be sure you select YES. The alias is set to go! Tables in that folder are now part of that database alias.

Why use an alias?

With my `Video` alias created (we’re back in dBASE now), I can use the Navigator’s drop-down list on the Look In field to select that database and make it “active”. In my case, rather than show C:\Myfiles\MyVideo, the Look In entryfield will display simply VIDEO. This tells me that tables I use and tables I create will belong to the `Video` database. If I click on the Tables tab in the Navigator, it should show me the tables created for that database (see screen shot below).

When you click the Look in drop-down arrow, you will see a list of your recently used folders, including their path. Scrolling further down the list, you will see a list of current aliases as defined within the BDE on your computer. Each alias has a small icon to its left. If the icon has a green “light” in the middle of it, the alias is currently active / open. Be sure that the alias you want to work with is the one showing in Look In.

Now I can expound a little on avoiding the “trap” I mentioned earlier.

Eventually, I’ll want to create forms for data entry which means I will drag tables from the Navigator to the form. When I do that, the Form designer creates code that references the table(s). If I had not created the `Video` alias and had that alias active (“VIDEO” appears in the Navigator window’s Look In field), the Form designer would create an SQL statement for the table along the lines of:

| `this.RATINGS1 = new QUERY()` `this.RATINGS1.parent = this` `with (this.RATINGS1)` `...` `sql = 'select * from C:\Myfiles\MyVideo\ratings.dbf'` `active = true` `endwith`

No doubt, this will work when the form is run. Imagine though that I create two dozen different forms using various tables and finally compile the completed program. After some time, I can almost guarantee that I or the user will want to move the tables to a different folder. Perhaps I will move the tables from a local computer to a network server. What happens now? Of course, my program no longer works because it can’t find the tables. So, my next move is to edit every form and change the path statement, recompile the program and re-distribute it to my users. Bummer!

Alias to the rescue

Since I have created an alias though, I don’t have the above problems. With the `video` database alias active, dragging a table to the form(s) results in different code. (Note: When you have an alias active, and drag the first table to your form, two icons rather than one will appear on the form. will represent the table/query while will represent the database/alias.) Instead of a hard-coded path, the Form designer assigns a simple SQL statement similar to:

| `this.VIDEO1 = new DATABASE()` `this.VIDEO1.parent = this` `with (this.VIDEO1)` `...` `databaseName = "VIDEO"` `active = true` `endwith` `this.RATINGS1 = new QUERY()` `this.RATINGS1.parent = this` `with (this.RATINGS1)` `...` `database = form.video1` `sql = "select * from ratings.dbf"` `active = true` `endwith`

In addition, the query object to which the above SQL statement belongs is assigned to the `video` database. Neither the program nor the Form designer knows (or cares) where the database is located, nor does it need to. It leaves that up to the BDE. When I decide to move the tables, I don’t need to change the program at all. The BDE Administrator just needs to be told where the database has been moved to and the whole mess is taken care of. How easy is that? Well, let me tell you!

You can update the BDE Administrator a couple different ways. The most obvious means would be to close your dBASE program, fire up the `BDE Admin` program, change the path, save it and be done.

Another method of doing this would be from within your program. A wonderful little custom control called `BDEAlias.cc` is available in the free dUFLP code library. With this little gem and a little imagination, you can allow the user to change the alias/database path from within the program.`BDEAlias.cc` is commented in regards to usage. Ken Mayer is the dUFLP librarian. You can download dUFLP from his site or from the dataBased Intelligence, Inc. site.

So, feel free to make your life easier by creating an alias at the beginning of the development cycle. You won’t regret doing so.

If you have any questions in reference to this document or if you wish to offer constructive criticism as to how I could make it better, please drop me an email at: website_dBulletin_@sehawks.com (take out “_dBulletin_”). I would like to hear from you.

Please note that I cannot supply technical support nor programming assistance of any kind for dBASE Plus, or any other software product. If you don’t do so already, I strongly recommend a visit to the dBASE newsgroups if you need assistance with dBASE. The place is overflowing with dBASE knowledge and techniques. Visit dataBased Intelligence, Inc. for further information on the newsgroup.

I would like to thank proof-readers Eric Bachleitner, John Fried and Gary Gibbs for improvements they brought to this text.