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.
#72332 by Jsosnowski
Mon Sep 18, 2017 3:02 pm
PART SIX - A DCAL FOR DELPHI PRIMER - OTHER MACRO CONSIDERATIONS

Once you have created your main function and added a Menu function to it, you are ready to begin coding your macro features. There are still plenty of challenges in developing a functional macro. This Post will discuss a variety of subjects including special situations, tips, strategies and whatever else may be useful for achieving your macro goals, a grab bag if you will. Each reply post covers a different topic.

Topics
1. Accessing Datacad Variables
2. Planning Delphi Units
3. Preserving variables with '.INI' files
Last edited by Jsosnowski on Mon Sep 18, 2017 3:55 pm, edited 2 times in total.
#72335 by Jsosnowski
Mon Sep 18, 2017 3:39 pm
Planning Delphi Units
Rev1 11/1/17 Added paragraph on data initialization procedure

For smaller macros all code can be placed in the initial library file unit created when you start a new '.dll' project (Delphi Menu: Project/New Project/DLL Library). Like in DCAL, for larger projects with a large body of operational options, it makes more sense to separate the code into multiple unit files (Delphi Menu: File/New/Unit-Delphi). Units offer a few capabilities that are not found in the library file. Units, for instance have multiple sections including:

1. interface - used to declare constants, types, variables, functions and procedures that are accessible to other units in the macro.
2. implementation - used to declare constants, types, variables not accessible by other units along with the code for all functions and procedures declared in the interface section or only available within this unit.
3. Initialization - used to declare any functions and procedures that should run when the unit is first opened at the start of the macro. Unit Initialization sections are opened in the order they are declared in 'uses' section declared in the 'library' project file.
4. Finalization - used to declare functions and procedures that should be run before the macro is terminated. Unit Finalization sections are opened in the reverse order they are declared in the 'uses' section declared in the 'library' project file.

Note that the library '.dll' file does not have these sections and every declaration made in the library will be accessible to other units.

Another important consideration for planning your units is that each unit must have a 'uses' section declaring any other units containing content in its 'interface' section that is used in this one. However, when compiling the code, Delphi will object any circular references. If 'Unit A' uses 'Unit B', the reverse cannot also occur. For this reason it may be a good strategy to create a single unit as a container to include all constants, variables, and types used in a single unit that does not have 'uses' links to other macro unit files.

Initialize your data
If a unit that contain global variables it is a good idea to create a procedure init_<name> to set initial values. Keeping this operation as separate procedure allow you to use it in a variety of situations. Certainly it should be used when the macro is started, but will also be useful if you are using data files and need to reset your data to an initial condition before loading the new data file. Variables such as string lists or other dynamic arrays will certainly need to be reset to a starting size in order to add the new data.

Once you begin coding macros it is difficult to stop. There is always another good idea that could simplify your work. By collecting related code in individual units it is possible to reuse them in other macros. One good example of this is the wrtutl.pas unit provided in Datacad's sample macro directories. This unit handles a variety of text display methods for use in displaying messages in Datacad. Another good utility unit might collect various methods for drawing various entity types in Datacad. Each new macro you write may add code to draw a different entity type. One unit holds them all and is easy to find the next time you need one of these previous functions.
Last edited by Jsosnowski on Wed Nov 01, 2017 1:01 pm, edited 1 time in total.

Who is online

Users browsing this forum: No registered users and 40 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