[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
forum.datacad.com • View topic - PART SIX - A D4D PRIMER - OTHER CONSIDERATIONS
Page 1 of 1

PART SIX - A D4D PRIMER - OTHER CONSIDERATIONS

PostPosted: Mon Sep 18, 2017 3:02 pm
by Jsosnowski
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

Re: PART SIX - Accessing Datacad Variables

PostPosted: Mon Sep 18, 2017 3:03 pm
by Jsosnowski

Re: PART SIX - Accessing Datacad Variables

PostPosted: Mon Sep 18, 2017 3:38 pm
by Jsosnowski
Oops - A duplicate. I 'll fill it in later.

Re: PART SIX - PLANNING DELPHI UNITS

PostPosted: Mon Sep 18, 2017 3:39 pm
by Jsosnowski
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.

Re: PART SIX - PRESERVING VARIABLES WITH .INI FILES

PostPosted: Mon Sep 18, 2017 3:51 pm
by Jsosnowski