The DataCAD Developer Network (DDN) is an online resource for information and support for DCAL® (DataCAD Applications Language) developers as well as anyone interested in creating fonts, toolbars, hatch patterns, or linetypes for use in DataCAD.

Moderator: pjdixit

#72033 by Jsosnowski
Tue Aug 08, 2017 11:35 am
PART NINE - A D4D PRIMER - REFERENCES, RESOURCES, & SETUP

Software
Delphi Starter Edition - This is a free download that gives you an IDE and access to online resources for writing and compiling D4D macros
DCAl for Delphi Package from Datacad - This is the package of tools necessary for Delphi to write the macros. It consists of five units which define the D4D envorinment to Delphi.
1. Uconstants.pas lists all of the constant values in DCAlr. Most of the constants are explained in theDCAl manual although some new ones were added for D4D specifically..
2. Uvariables.pas lists all Datacad variables accessible in macro programs. Most of the variables are explained in theDCAl manual.
3. Urecords.pas lists all of the record types used to store data specific to various Datacad entities, layers, and other operational features.
4. Uinterfaces.pas lists all user interface methods used in D4D. These are the methods that require user input and conclude the portion of a menu loop iteration contained in the Macro. Control of the loop must pass out of the macro and into Datacad whenever these methods are called.
5. UinterfacesRecords.pas lists all of the record structures used to pass data to/from the interface method when control changes between Datacad and the D4D macro.


Experience

The Postings in this series assume that the reader has a basic understanding of Pascal, Delphi and DCAL. It is a primer on how to implement DCAl for Delphi (D4D) macros and convert DCAL macros into D$D format.

Recommended References
DCAL Manual - (available as a download In 'Word' format at Datacad.com) Although written for DCAl it is essential for understanding various constants, variables, records and methods used to create a D4D macro. Interface methods, in particular have new arguments requiring different coding techniques to operate them, but the basic functions remain the same. Later PARTs will explain how to handle the different method arguments effectively.

Delphi in a Nutshell - ADesktop Quick Reference[/u] Ray Lischner, c2000 - O'Reilly & Associates. This is a comprehensive reference manual for Coding in Delphi. It is essential to writing Delphi code. The first section of the book covers many of the basic features in Delphi that extend the language from Pascal.

Oh! Pascal Second Edition Doug Cooper & Michael Clancy, c1985, 1982 - W.W. Norton Co., Inc. This book starts with the simplest pascal programming techniques and walks you how to use the full range of capabilities provided in the Pascal programming language.

Object Pascal Language Guide - c1983, 2002 - Borland Software Company. (Available as an online free 'pdf' download.) This book provides detailed explanations expanding the pascal language to include full object oriented programming structure.

Mastering Delphi Delphi 6, 7 - Marco Cantu - 2001 Sybex. (Also available online as free downloadable pdfs.) These books are enormous (running more than 1,000 pages) and cover a large swath of Delphi capabilities. They will be of great assistance in learning how to make windows style forms using the available graphic components in Delphi. There are later versions covering features added in later versions of Delphi, but these two cover many of the basics.

Setup

Installation:

Delphi Starter Edition (v10). This is the free edition of Delphi available for download from their website. The installation process is familiar and should provide you with an operating copy of the program. After it is installed you will need to perform several setup tasks to work on macros.

1. Setting Unit Directory Paths. Selecting the menu 'Tools/Options' brings a popup dialog. Select 'Environment Options/Delphi Options/Library' and choose the 'Library path '...' button. This will give you a list of the current directory paths that Delphi uses to search for unit files in your programs declared under the [color#0040ff]uses[/color] section. You must add the directory in which you will be placing your DCAL unit files so that Delphi can find them. To add a new directory select the folder icon button, browse to your desired path and select the add button.

2. Setting Macro Output Paths. Compiled macros are saved to a specified directory. You will want to redirect the macro files to the Datacad Macro directory so that they can be found by Datacad. The setting for this can be found in the Delphi 'Project/Options' menu calling a 'Project Options' popup dialog. Select the 'Output' '...' button to browse to the 'Datacad/Macros' directory. (At the time of this posting, it appears that this option must be set separately for each macro project written. Please post if you find a different option in Delphi that sets this option for all 'dll' projects.
Last edited by Jsosnowski on Sun Sep 17, 2017 8:11 pm, edited 1 time in total.
#72271 by Jsosnowski
Mon Sep 11, 2017 4:49 pm
Debugging

Delphi's IDE includes a debugging feature that can be used to monitor the flow of your macro and the value of variables as the macro is executed. To get started, you must configure Delphi to work with Datacad in several steps. Note that these settings are specific to the project that is open, so you will have to perform this setup for each macro project you create.
1. Begin by opening the macro project file in Delphi.
2. Select the menu 'Run/Project Options' and pick 'Delphi Compiler' from the popup menu list and set the Output directory to your Datacad/macro path (eg. C:\DataCAD 19\Macros\).
3. In the same popup menu list select 'Debugger', browse for the path of the Host Application to pick DCADWIN.EXE, and set your working directory to the macro path (C:\DataCAD 19\Macros\). Finally select OK in the popup to save your settings.

Once you have things configured you can instruct what to watch in the macro.
4. Select Ctrl+Alt+W to view a watch window where selected variables can be monitored. By placing the cursor in the code on a variable and selecting ctrl+F5 the variable will be added to the watch window. When you start the debugger, the values for each variable will be selected in the window whenever they are in scope. By stepping through the code you can watch as the values of variables change.
5. You can also create Break points in the code. When you start the macro code will execute until it encounters a break point and stops. You can then execute the code one line at a time by using the trace into or step over options in the 'Run' menu or button bar. In this way you can follow the path of code execution.

Finally you can test the macro by selecting the 'Run/Run' menu option (or buttonbar option) to begin the debugging session. Delphi will open Datacad, display the 'Watch' window, and wait for you to open a file and select your macro. Once the macro is selected, the screen will jump back to Delphi as it executes code up to your 'Break Point'. You can then step through your macro monitoring values and path as you go. You can end your debug session at any time by selecting 'Run/Program Reset' from the Delphi menu.

Thanks to Dave Henderson for debugging my Delphi configuration to run the debugger in macros!

Who is online

Users browsing this forum: No registered users and 1 guest

About DataCAD Forum

The DataCAD Forum is a FREE online community we provide to enhance your experience with DataCAD.

We hope you'll visit often to get answers, share ideas, and interact with other DataCAD users around the world.

DataCAD

Software for AEC Professionals Since 1984