Source Code Aliasing
by Ken Mayer, dBASE QA

WITH THE RELEASE OF dB2K release 1, it would be useful to have an idea what is meant by “Source Code Aliasing”, and why it is useful to you, the developer.

Have you ever wanted to store all of your code in a library, and not have to worry about where it was stored? How about being able to move it and change references in your code only once? This is similar to the way a BDE Alias works now.

Well, Alan Katz, the CEO of dBASE, Inc., saw this as something that would be useful for your source code libraries, and it's been added to dB2K in release 1.

Even better, you can have a multitude of source code aliases.  Does this sound like a good idea? You bet it does. Someone who was REALLY organized could store their custom forms in one directory, their custom reports in another, have an alias set for the dB2K Users' Function Library, and so on.

So, the question is, how do you set it up, and how does it work?

Setup is very easy. There's a new tab in the properties dialog in the dB2K IDE (Integrated Development Environment). To see it, click on the “Properties” menu, and select “Desktop Properties”. Click the right button to see the tab to the far right that says “Source Aliases”. (Note: You can also access the Desktop Properties dialog box from the Command window by typing “set”.)

To create an Alias, enter a name in the “Alias” entryfield, and set the path, either by typing it in, or by using the “tool” button (this brings up the standard get directory dialog). When you have everything “just right” click on the “Add” button, and there you go. What did that just do? It wrote information to the DB2K.INI file in your BIN folder. The entry might look like:

  [SourcePath]
  MyAlias=C:\dB2KTests\MyCode

And you can add or remove your aliases as you need to, and you can change them using this dialog.

Now how do you use this?

The simple way is to use it like you would a database alias in XBase DML. If you wanted to refer to a table stored in a database in XBase DML, you would use:

  use :databasealias:tablename

If you want to run a program that is stored in a directory referenced by an alias, the syntax is:

  do :MyAlias:Myprogram

    or

  set procedure to :MyAlias:MyProgram additive

If you want to run a form:

  do :MyAlias:MyForm.wfm

    or

  set procedure to :MyAlias:MyForm.wfm additive
  fMyForm = new MyFormForm()
  fMyForm.open()

(and so on ...)

There are some places that you need to be careful with your syntax, mostly with custom forms, custom datamodules, and custom reports. An example would be a custom form where you wanted to reference this using the source alias “TestAlias” as shown above. All you have to do is change the reference in the source code editor that looks like:

  class testformForm of TESTCUSTCFORM from "C:\dB2KTests\MyCode\mycust.cfm"

to read:

  class testformForm of TESTCUSTCFORM from ":MyAlias:mycust.cfm"

Note that this works for custom datamodules and custom reports exactly the same way.

Where can you use source code aliases?

   Programs
   Forms
   Custom Forms
   Custom Controls
   Form.menuFile property
        (e.g., fMyForm.menuFile = ":MyAlias:mymenu.mnu" )
   Popup menu
        (e.g., set procedure to :MyAlias:MyPopup.pop additive )
   Image.dataSource property
        (e.g.,fMyForm.image1.dataSource = "FILENAME :MyAlias:MyImage.gif" )
   Reports
   Custom Reports
   ReportViewer.filename property
        (e.g.,fMyForm.reportViewer1.filename = ":MyAlias:MyReport.rep" )
   Labels
   Datamodules
   Custom Datamodules
   SQL Files

Other examples:

  Pushbutton.disabledBitmap = "filename :MyAlias:MyImage.bmp"
  Pushbutton.downBitmap = "filename :MyAlias:MyImage.bmp"
  Pushbutton.focusBitmap = "filename :MyAlias:MyImage.bmp"
  Pushbutton.upBitmap = "filename :MyAlias:MyImage.bmp"
  Form.background = "filename :MyAlias:MyImage.bmp"
  Form.icon = "filename :MyAlias:MyIcon.ico"
  Treeview.selectedImage = "filename :MyAlias:MyIcon.ico"
  Treeview.checkedImage = "filename :MyAlias:MyIcon.ico"
  Treeview.Image = "filename :MyAlias:MyIcon.ico"
  Treeview.unCheckedImage = "filename :MyAlias:MyIcon.ico"
  Menu.checkedBitmap = "filename :MyAlias:MyImage.bmp"
  Menu.unCheckedBitmap = "filename :MyAlias:MyImage.bmp"
  PageTemplate.background = "filename :MyAlias:MyImage.gif"
  Toolbutton.bitmap = = "filename :MyAlias:MyImage.bmp"

Once you have this set up in your source code, what happens when you create a .EXE file? The source code aliases are ignored. If the project for your executable is set up correctly, you will have included all of the files that are needed for the project in the .EXE, and you will have no  problem. This is necessary with or without the use of the source code aliasing in dB2K.


Note: The author would like to thank Flip Young, my proof-reader, for the improvements she brought to this text.