Topic Title

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.

Converting older DCAL macros into D4D macros is reasonably straight forward,but somewhat tedious process. The first step is to load your old DCAL code inin a simple text editor such as Notepad++ and run several search and replace cycles to convert from DCAL to the Delphi language. Changes include:

Although the the final 'end;' can be dropped if the 'doSomething; code is only one line long, it is simpler to keep the 'end' statement in place both for search and replace and for future additions. Therefore search for 'then' and replace it with "then begin'.

ELSIF statementsThe 'elsif' statement does not exist in Delphi. There are two alternatives to correct it. 1. Search for 'elsif' and replace it with 'end else if '. 2. Delphi includes the 'case condition of' statement structure which reads simply in your code. You can easily assemble 'case' statements individually to replace 'elsif' cascades in your code.

The 'RETURN;' keyword aloneThe return keyword used alone is used to end processing a method before reaching the method end. Delphi does not recognize the keyword 'return' and uses the keyword 'Exit' instead. Search for 'Return;' and replace with 'Exit' (without a semicolon).

The 'Return value;' keywordDelphi uses a built in function variable called 'result' for function return values. Replace the term by searching for 'Return' and replacing it with 'result := '.

For/Do and While/Do statementsThese multiple line statement structures must be enclosed with 'begin, and 'end;' keywords. For 'For/Do' and 'While/do' statements Search for the word ' do' (include a leading space to avoid 'do' contained in words) and replace with ' do begin'.

End of method code line Datacad methods conclude with a last line reading 'end <methodname>; while Delphi methods do not include the method name. To correct this manually move to the end of each method and insert '; //' after 'end' converting the method name to a comment.

! CommentsThe '!' is not recognized by Delphi for a line comment. Search for '!' and replace it with '//'.

Global Unit VariablesDCAL units include provisions for persistent global variables declared in units outside of methods. Whenever a macro is closed, the current value for these variables is saved in the macro file '*.dcx'. Delphi does not include these persistent variables so another strategy must be used.

Initialization methodsMany DCAL macros include a method such as 'procedure InitData;' to set initial values for a macro. The call for this procedure is usually placed in the DCAL Macro program starting method for the macro and checks a global variable such as 'Used: boolean;' to determine if the macro variables have been given initial values. Boolean variables are initiated as false so 'Used' will equal false on its first use meaning that InitData should be called. 'InitData' will then set 'Used' to true, preventing reinitialization in later macro runs. Unfortunately, Delphi unit variables are not stored between uses so this initiation strategy will not work. Delphi provides a unit section called 'Initialization' that serves the same first time purpose. However, to preserve these variables between uses of the macro they will have to be saved and retrieved using a file. One way of doing so is discussed in PART SIX using 'ini' files.

Accessing Datacad VariablesThe DCAL manual lists numerous program variables that are accessible in DCAL. D4D declares these varaibles in a in a packed record called 'savevar' in uvariables.pas,although many have modified names. requiring all variables to be checked and renamed in your revised code. To access these variables you must use the function PGsavevars; to read or write the specific field as in the following code line:.

Method Public DeclarationsDCAL requires two files for each unit file used in a macro. 'UnitA.inc' and 'UnitA.dcs'. The '.inc' file contains declarations including a list of all methods which are to be accessible to other units in the program. The '.dcs' file contains the actual methods including a 'PUBLIC;' declaration ending each methods declaration line. Delphi moves all unit declarations into the same unit file under the section heading 'interface'. Copy the contents of your '.inc'. file into the unit under the 'interface' section keyword. Move your '.dcs' functions into the unit file under the 'implementation' section keyword and remove the 'public;' term from methods.

Character LiteralsDCAL uses double quotes " to bracket character literals (eg. "c"). Delphi uses single quotes. A simple search and replace should cover all code line occurrences.

Thanks for the advice Joe. I am in the process of converting some code and found your comments most helpful.

I also took it a bit further by automating many of the steps using Notepad++ macros.So far I have developed 3 Notepad++ macros:

Replaces does pretty much all of the straight text replacements outlined in Joe's post in just one step. My macro is assigned to the Shift/Alt/R key in Notepad++. This macro just needs to be run once to do all the replacements

StrAssign macro automates the process of replacing DCAL StrAssign statements with the string assignement used in Delphi. I have assigned this macro to Shift/Alt/A. This macro searches for and corrects one instance of StrAssign at a time. You can run it multiple times automatically, but if doing so I recommend adding the word 'StrAssign' to a new line at the very end of your file before running (as the macro will corrupt the line the cursor is on if you run it and there are no more instances of 'StrAssign' in your code). I find it easier to just press Shift/Alt/A repeatedly until I hear a warning beep (the beep indicates the macro could not find an instance of StrAssign, so I then need to press Ctrl/Z to undo the last thing that it did)

StrCat macro automates the process of replacing DCAL's StrCat with the correct Delphi syntax of adding strings together. I have assigned it to Shift/Alt/C and run it in a similar way to StrAssign (as it will also corrupt the line the cursor is on if it does not find another instance of 'StrCat').

If you are using Notepad++ then you can add these macros by copying the code below into the <Macros> section of the shortcuts.xml file that is found in your 'C:\Users\<UserName>\AppData\Roaming\Notepad++' folder (replacing '<UserName>' with your user name of course). Ensure that you don't have any existing user-defined macros assigned to the keys that I have assigned before just copying this in:

InOut fixes IN OUT parameters. Invoked by Shift/Alt/I and fIxes one at a time and same comments apply to automatically running it multiple times as the the macros in my previous post.

In fixes IN parameters. Must be run after the InOut macro above (otherwise it will corrupt all your IN OUT parameters). I found I use the word 'IN' in comments quite a bit, so you need to watch and undo when it modifies a comment (and make sure the cursor is on the following line before you invoke the macro again). Same comments regarding multiple runs as for above macro.

Here is the xml code for the macros (insert into the <Macros> section of the same file as specified in my previous post)