• No results found

Making Visual LISP Applications

In document Vlisp Dev Bible (Page 92-98)

Probably the most significant feature provided by Visual LISP is the capability to build and manage applications. In this context, we are really talking about VLX applications, but you could consider FAS output to be applications as well. The building of Visual LISP applications is closely tied to the use of Projects, but they are not inseparable.

Why Make VLX Applications?

The main reasons for making VLX applications are improved security and performance.

Security is improved because the Visual LISP compiler encrypts and compiles the source LSP code into binary output that is unreadable to the human eye. It also can combine multiple LSP files into a single VLX output further improving security and providing a single output for delivery to users. Performance is improved because the compiled code is actually more efficient to execute at runtime.

Unlike many other programming languages, Visual LISP does not truly “compile” its output, but more accurately performs an encryption and partial compilation. This is somewhat like what a Java compiler does to produce “p-code” output, which is then compiled at runtime by the JVM (Java Virtual Machine) compiler on the client. Visual LISP VLX code is compiled to binary output but not to machine level language, meaning it must be interpreted at runtime by the client. It still provides some measure of performance improvement over raw LSP source code though.

FAS files are an intermediate output during the VLX compilation that are the product of the LSP file compilation. The VLX module combines FAS files and any other file types to wrap it all up as a single loadable module on the client. VLX applications can include other file types such as LISP, Dialog Control Language files (.DCL), Compiled LISP code (.FAS), VBA compiled files (.DVB), ASCII TEXT (.TXT) and even other VLISP Projects (.PRV).

One of the most useful features of making VLX applications is that you can combine multiple files into the single VLX output. This makes for easy loading and management as well as keeping your deliverable product clean and compact. Let’s try an example.

Building a Simple Application

Open the FirstApplication.LSP file in Visual LISP from the book samples CD. Then open the FirstApplication.DCL file in Visual LISP as well. Now, pick File/Make Application/New Application Wizard from the pulldown menu. There are two modes for compiling VLX applications: Simple and Expert. Simple used when you are only going to compile LSP files and do not intend to compile a separate namespace VLX. Expert mode allows you to include additional Resource files such as DCL, DVB, VLX and others within the VLX as well as make it a separate namespace application.

Since in this exercise we will be compiling a LSP file with a DCL file into a single, separate namespace VLX application, you have to select the Expert mode from the Wizard Mode panel (Figure 13-1). Pick the Next button.

Figure 13-1 – Make Application Wizard

The Application Directory panel (Figure 13-2) is where you specify the VLX filename and target output location. The Application Location is where you want the VLX file to be created at the end of the process. The Application Name is the name you want to call the VLX file (don’t include the extension, only the base filename). You will see that while you type in the Application Name box, the Target File window shows the actual VLX filename result. Once you’ve specified the Application Location, and entered the Application Name “FirstApplication”, pick the Next button to continue on.

The Application Options panel (Figure 13-3) prompts you to make this a Separate Namespace application, as well as use ActiveX Support. For this example, check both options, and pick Next to continue.

Figure 13-3 – Application Options form (Separate Namespace checked)

The LISP Files to Include panel (Figure 13-4) is where you select the LISP code files (*.LSP) to include in your VLX application. Pick the Add button to browse for, and select the FirstApplication.LSP file. Then pick Next to continue.

Figure 13-4 – LISP Files to Include form

The Resource Files to Include panel (Figure 13-5) is where you select additional resource files, such as DCL dialog form files, DVB (VBA) files, and other types of files. Change the file type selection to DCL Files and pick the Add button to locate and select the FirstApplication.DCL file. Then pick the Next button to continue on.

Figure 13-5 – Resource Files Include form

The next panel prompts you to choose either Standard or Optimized compilation. For this example, use the Standard option and pick Next to continue.

Figure 13-6 – Application Compilation Options form

The final form asks if you want to save the Make Application settings and go ahead and compile the VLX application. If you choose not to compile, the settings you just configured are saved to a make file that uses a .PRV file extension. You can reuse make files at any time to recompile using the stored settings and save a lot of time. For this example, go ahead and compile your VLX application by picking the Finish button.

Figure 13-7 – Review selections and build application form.

Now that you’ve compiled FirstApp.VLX you can load it into AutoCAD and try the FIRSTAPP command to see how it works. You should see a dialog form with one OK button and a message displayed saying “Congratulations!” in the middle.

If this doesn’t happen, review this chapter to make sure you followed all steps correctly and compile and load it again. To reload a separate namespace VLX you first have to unload the existing definition by using the (vl-unload-vlx) function. To unload FIRSTAPP, you would use (vl-unload-vlx “firstapp.vlx”) at the command prompt.

Figure 13-8 – Results of running the FIRSTAPP command.

PRV Files

The Make Application Wizard creates a PRV file to store the settings for your application. If you open a PRV file in notepad, you will see that it is actually a LISP formatted file in which the properties are stored as dotted-pair lists. The example below shows a PRV that compiles a LSP and a DCL file into the ASW_PM.VLX output.

;;; Visual LISP make file [V1.0] asw_pm saved to:[C:/ASW/SYS]

at:[3/15/02]

(PRV-DEF (:target . "asw_pm.VLX") (:active-x . T)

(:separate-namespace) (:protected . T)

(:load-file-list (:lsp "source/asw_pm.lsp")) (:require-file-list (:DCL "source/asw_pm.DCL")) (:ob-directory)

(:tmp-directory) (:optimization . st) )

;; EOF

Although you might be tempted to “tweak” PRV files in a text editor, you should instead use the “Existing Application Properties” feature to modify the PRV configuration settings. Editing the PRV file manually may corrupt the file and cause errors when you attempt to recompile.

In document Vlisp Dev Bible (Page 92-98)