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.
#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!
#73095 by Jsosnowski
Wed Jan 17, 2018 12:43 pm
Version Control using GIT

It doesn't take long after beginning to program in any language before the coder finds themselves needing version control to manage the development of their program. For instance, you are developing a macro, writing code, regularly testing it, and after it succeeds, moving on to the next development issue. In fact, you may be working on more than one issue, moving along on both paths, when you suddenly find that your macro no longer works correctly, including things that did before. What do you do? Clearly you have created a conflict in your code and need to back up, but where is the problem and what to change. Without an operating macro it is very difficult to identify the problem code lines. The coding community solved this problem long ago using version control. To solve the problem it is necessary to back up your versions until you find the last operating version and then compare that with the current version. There are plenty of strat4egies and software options accomplishing this, but the most common is a program called GIT. GIT is a free software package that permits multiple users to work simultaneously on the program code permitting each user to create multiple versions as their program development progresses. GIT tracks everyone's contributions and allows them to be easily joined. Each developer can easily backup versions and compare different versions to identify changes.

GIT was originally developed by the creator of the linux operating system and is a command line operated language. Seasoned programmers will master the commands and manage GIT version control from the command line, and there is plenty of them to learn. For those who are more visually oriented (say architects & engineers?), GIT can fortunately also be used from a Graphic User Interface (GUI) which youadd to GIT to take command of the GIT command line. There are several GUI programs on the web both for sale and for free. It is easy to compare features online and I cannot say I have done an exhaustive review of features. What I can do is make a suggestion based upon my experience based upon my exploration of several programs before settling on one I like. The program 'SourceTree' offers a fairly comprehensive, easy to learn interface, that encapsulates much of the command line functionality. What is more important is there are a series of YouTube videos that do an excellent job of explaining how GIT works and how to use SourceTree to operate GIT. It is possible to get a solid working understanding of GIT and SourceTree in a single day.

There is one more piece of software to add to your library, 'KDiff3' which is used with Sourcetree. As the videos will explain, sometimes, when GIT is merging two branches in your code, there will be conflicts between the two version which must be resolved by the the code author. 'SourceTree' uses 'KDiff3' to display each conflict in the code for resolution. Once you resolve the conflicts, SourceTree completes merges.

Sources:
GIT: https://git-scm.com/
SourceTree: https://www.sourcetreeapp.com/
KDiff3: http://kdiff3.sourceforge.net/
Tutorials: https://www.youtube.com/watch?v=UD7PV8auGLg

The SourceTree tutorials are produced on a YouTube channel called Virtual Play: https://www.youtube.com/channel/UCR6wQwL5XkbVhwD7qS6MAPg At the time of this posting there are six videos. Be sure to like the videos to encourage the autors to make more on advanced features.

Who is online

Users browsing this forum: No registered users and 8 guests

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 Architects Since 1984