
|
- Written and documented by David Deley
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12.1: 12.2: 12.3: 12.4:
Introduction to CMac Chapter 3: Caveats
There are a few differences between CMAC and other programming
languages you may be familiar with, like C. These are small things you
often end up learning the hard way, by experience. I mention these
early on so you'll be aware of them. I also encourage others to append
other caveats they've learned.
2. SINGLE QUOTED STRINGS vs. DOUBLE QUOTED STRINGS Double quoted strings interpret the backslash \ character as a special character.
* "\t" will enter a 0x09 horizontal tab character if "Tab Expand" is set to "Tabs" under TOOLS -> CUSTOMIZE... -> Editing, or it will enter a 0x20 space character if "Tab Expand" is set to "Spaces". Two double quotes together inside a double quoted string make a double quote:
same as:
Single quoted strings interpret the vertical bar | character as a
special character. A vertical bar followed by a number will insert that
character value. A few examples:
Two single quotes together inside a single quoted string make a single quote:
Result:
3. MACROS MUST BE EITHER PROTOTYPED OR DEFINED BEFORE THEY ARE CALLED BY OTHER MACROS.
The other way is to prototype macro "mysub" at the beginning of the
file. The following will work even though macro "mysub" is defined
below macro "test" which calls it:
4. WINDOW ID vs. WINDOW NUMBER
A window's ID will not change. I therefore recommend you always work with window ID's and use 'TranslateWindowID' to get the window number when you need it. Window numbers are useful when you want to cycle through all existing windows. It turns out that the Switch_Window system function has an undocumented feature. The documentation says it accepts a window number to switch to. But it is also smart enough to also accept a window ID. A window number is a number between 1 and 127 (or maybe 255, I'm not sure what the upper limit is). On the other hand a window ID has the lower 16 bits set to zero, so in hex a window ID looks like 0xnnnn0000. Thus it is easy to tell a window number from a window ID. Note this is undocumented so you should always use a window number with Switch_Window.
5. STRINGS ARE 254 CHARACTERS UNLESS YOU SPECIFY A LENGTH
then your string MyString is only 254 characters long (that is, the string will hold 254 characters and no more). If you need a longer string you have to specify the length.
MAX_LINE_LENGTH is a system constant (currently 16383) you can use to specify the longest possible string:
6. EXPLICIT STRINGS IN CMAC CODE
7. GLOBAL VARIABLES
This does not cause a problem, because if you reference a non-existant global integer you will get zero (0), and if you reference a non-existant global string you will get "" (zero length string).
GLOBAL ALIASES
Here Disp_Str is your global alias you can use like a local variable, and !CALC_DISP_STR is the global variable created. (Some CMAC functions require a local variable and will not accept a global alias. You may equate a local variable to the global alias and then use your local variable.)
If instead you were to just declare
then the global variables created are the same as the alias names. Global variables with names not preceded by a ' ! ', '@', or '~' are restored at the beginning of each editing session if the restore feature is enabled. (This is often not necessary or wanted, which is why so many global variable names start with '!' or '@'.)
8. DlgAddCtrl and ctrlid
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12.1: 12.2: 12.3: 12.4: |