Building Dockable Forms for
AutoCAD 2000 with Delphi
Copyright ©1999 Tony Tanzillo
Warning: This document and all accompanying material are the sole property of the author, and are protected by copyright laws and international treaties. This document and its accompanying materials my not be reproduced or redistributed for any purpose, without the expressed, written consent of the author.
The AutoCAD Dockable Container (AcCont) is an AutoCAD Runtime Extension that provides a floating/dockable container for ActiveX controls. The dockable container allows you to build modeless, dockable windows for use in custom-developed AutoCAD Applications.
These dockable windows can float above the AutoCAD window in a modeless state, or may be docked to any side of the AutoCAD window, just like AutoCAD's built-in tools (such as Design Center and the Properties dialog). What makes the Dockable Container attractive to Delphi programmers is that it can be used to host not only Delphi-based ActiveX controls, but Delphi ActiveForms as well.
The Dockable Container was developed by Jorge Lopez, a former Autodesk programmer. The author would like to express his sincere appreciation to Mr. Lopez for taking his own time to develop this excellent tool, and making it freely available to all AutoCAD programmers.
The screenshots below show several examples of what can be achieved with the Dockable Container and Delphi ActiveForms.

In the following screenshot, the docked window on the right is not AutoCAD Design Center. It is a Delphi ActiveForm hosted by a dockable container.

The following instructions detail how to build a Delphi ActiveForm that can be hosted by the Dockable Container. Note that source code is shown in white on a blue background, and modifications to the source that are described by the instructions, are shown in bold yellow type. A link to the completed source for the sample project created by following these instructions can be found at the end of this document. These instructions are intended for use with Delphi 4 or 5 and AutoCAD 2000. In addition, the AutoCAD Dockable Container runtime module is required, which can be found at the end of this document.
First, you must import the AutoCAD 2000 type library, and AcCont type library into Delphi. This needs to be done only once.
Importing the AutoCAD type library produces a file in your /Imports folder called AutoCAD_TLB.PAS. If you haven't imported the AutoCAD type library you can do so by following these steps:
1. Start Delphi.
2. If Delphi creates a new project when you start it, then close the new project without saving.
3. From the Project menu, choose "Import Type Library".
4. In the Import Type Library dialog, Choose the "Add" Button, and then navigate to and select the file "Acad.TLB", which is located in the same folder as ACAD.EXE. Once you've done this, the list should contain the highlighted item "AutoCAD (version 1.1)". If this item is not highlighted then select it now.
5. The Unit Directory Name should be set to the "Imports" folder within your Delphi folder. If this is not the case, then change it to that folder.
6. Click OK, and Delphi generates the Object Pascal Unit named "AutoCAD_TLB.PAS". Close this file.
Next, import the ACCONT type library. Before you do this, AcCont.arx must have been previously loaded into AutoCAD as an ARX file to register it.
1. Start Delphi.
2. If Delphi creates a new project when you start it, then close the new project without saving.
3. From the Project menu, choose "Import Type Library".
4. In the Import Type Library dialog, scroll the listbox to, and then select the entry named "AutoCAD Dockable Container Type Library 1.0".
5. The Unit Directory Name should be set to the "Imports" folder within your Delphi folder. If this is not the case, then change it to that folder.

6. Click OK, and Delphi generates the Object Pascal Unit named "AC_CONT_TLB.PAS". Close this file.
Now you are ready to create a dockable container client in Delphi. To do so, follow these instructions:
1. Start Delphi.
2. From the File menu, choose New...
3. On the New Item dialog, choose the ActiveX tab.
4. Double-click the "ActiveForm" Icon.
5. In the ActiveForm Wizard dialog that appears, Specify the name of the Form, Unit and Project. Note that these instructions assume that you enter the following for these values:
| New ActiveX Name: | TestForm |
| Implementation Unit: | TestFormImpl1.pas |
| Project Filename: | AcDockForm |
Note that the ProgID of your form will be the Project name followed by a period and the Form name. Hence, with the above values, the ProgID will be "AcDockForm.TestForm".

6. Click OK, and Delphi generates the project.
7. From the File menu use Save Project As, and save the project and unit to a separate folder, keeping the same filenames used in step 5.
Next, we must add the Ac_cont.tlb type library unit to our project:
8. From the View menu choose "Type Library".
9. In the AcDockForm.tlb Type Library Window, Select the root
node of the treeview, with the label
.
10. In the right pane, Click the "Uses" tab.
11. Right-click over the listview and choose "Show All Type Libraries".
12. In the listview, scroll down to and place a check next to the item "AutoCAD Dockable Container Type Library".
13. Right-click over the listview, and choose "Show Selected". At this point, there should be three items shown in the listview, all checked.

14. In the Code Editor Window, Activate the TestFormImpl1 unit.
15. At the top of the unit, in the interface section, you will see the following uses clause:
|
16. To the above uses clause, add the names of the AutoCAD type library (AutoCAD_TLB) and Ac_cont type library (ac_cont_tlb) import units.
After adding these units, your uses clause should look like this:
|
Next, you must add support for the IAcadDockableContainer2 interface, that allows your ActiveForm to communicate with its dockable container:
17. From the View menu, choose "Type Library".
18. In the TreeView, select the third child node, named
.
19. In the right pane, click on the "Implements" tab. The listview in the right pane should now show two items (ITestForm and ITestFormEvents).
20. Right click on the listview, and choose "Insert Interface".
21. In the ListBox, scroll down to and select IRetrieveDockableContainer2, and click OK.

22. In the type library editor window, click the
Refresh button.
23. Switch to the TestFormImpl1 unit in the code editor, and your ActiveForm's class declaration ancestry list should look like this:
|
24. Preceding the FEvents field declaration in the private section of the ActiveForm class, add the following private field:
FDockContainer: AcadDockableContainer2;
After inserting the above field, the beginning of the ActiveForm's class declaration should look like this:
|
24. In TestFormImpl1.pas, scroll to the bottom of the file, and locate the following method implementation:
|
25. Modify the above procedure as follows:
|
27. This completes all code modifications needed to use the ActiveForm in a dockable container.
28. Next, switch to the Form Designer which shows your ActiveForm, and in the Object Inspector, change the ActiveForm's AxBorderStyle property to afbNone.
29. Add two TButtons to the ActiveForm. Delphi will give them the names Button1 and Button2.
30. Select Button1 in the form designer, then in the object inspector, change the button's caption to "Dock". Then select Button2 in the form designer, and change its Caption to "Float".
31. Select Button1 in the form designer and then in the Object Inspector, click the "Events" tab.
32. Double-click on Button1's OnClick event. Delphi inserts the following procedure into the code editor window:
|
33. Modify the above procedure to the following:
|
34. Select Button2 in the form designer, and then repeat step 32, and modify Button2's OnClick event handler as follows:
|
35. Save all open files, and Build the project.
36. From the Run menu, choose "Register ActiveX Server".
You are now ready to test your Dockable Form.
1. Start AutoCAD.
2. AcCont.arx should load automatically. if it does not, then issue (arxload "accont.arx") on the AutoCAD command line.
3. Issue the DOCKABLE_CONTAINER command, and enter "AcDockForm.TestForm" at the prompt, as shown here:
Command: DOCKABLE_CONTAINER
Name of control (ProgID or CLSID): AcDockForm.TestForm
Your Dockable Form should now be visible. Click the Dock or Float buttons to dock or float the form.

Well, there you have it. With relatively little effort you have created a slick, professional looking user-interface for your Delphi-based custom AutoCAD application.
Project
Source (SOURCE.ZIP)
AutoCAD Dockable Container Runtime Module (AcCont.zip)
AutoCAD 2004 Dockable Container Runtime Module (AcCont16.zip)
C#.Net Dockable Container Control Sample (VS.Net 2002)
Tony Tanzillo is the owner of Design Automation Consulting, a small consulting firm that provides custom-developed AutoCAD solutions and related services. He has been active in AutoCAD programming and customization for the past 15 years, and has authored several books and dozens of periodical articles about AutoCAD customization and AutoLISP programming. Additional information on AutoCAD programming with Borland Delphi can be found on his web site.