** 2 page tutorial / 982 words ** Strings in Resources George Crissman invites you through the pain barrier... Recently, I was asked what is so "recreational" about computer programming anyway? The answer, mom, is two-fold: ** UL ** * A feeling of accomplishment and mastery when a program finally compiles and does what it's supposed to do. * Plus you can make the computer do things no one else will make it do, like pulling text from intentionally unused dialog boxes. ** /UL ** ** R_MOUSES.GIF ** ** caption ** "Right Mouse Pressed" is copied from an unused dialog box for window display. ** /caption ** One of the most important functions of any computer program is to present information to the operator in easy, readable text. In "computerese", lines of text are referred to as "strings", since the computer takes a bunch of individual characters and "strings" and puts them together into one long line. It's common for C programmers to simply put user messages into the actual code, since the language has good string-handling ability. While this string-in-code technique is easy, simple, and quick to implement, it manages to violate a key facet of GEM: all of the operator display is supposed to be in the resource file. Keeping the messages separate makes updates easy and simplifies the process of translating your program into another language without editing the code itself. Anyone who's ever made a "minor change" in a program, only to discover afterwards that it crashes horribly, won't start or won't even compile knows the value of the resource file! The Stringways Case Recent Usenet hubbub centred on the ability (or lack thereof) of a program to detect a click of the RIGHT mouse button. The method was originally undocumented by Atari, then revealed to registered developers, then improperly documented in public, finally resulting in a free-for-all in the comp.sys.atari.programmer newsgroup where I had to admit I was wrong - thanks, guys! During the on-line melee, a test program was developed which demonstrates how to detect a right mouse button click. Since it also demonstrates the "strings from an unused dialog" concept, we will take a closer look at it. If you want to know more about right button detection, run the program and read the listing on the Reader Disk. ** BORNPREG.GIF ** ** caption ** Display clutter caused by the free string technique ** /caption ** The designers of GEM allowed for general-purpose text by using a "free string" in the resource construction set. Implementation is fairly simple, too. Just give the string a name, input the actual string to be used, then link to the string from your program using rsrc_gaddr(). The big drawback is having to create a link for every individual string - and the resultant disorganisation in the resource window. The temptation to use the same string in two places can lead to trouble later on if the meaning in one of the two locations must be changed - time for a little recreational programming! Sorry, Doctor, No ** WIN_HEAD.GIF ** ** caption ** This form will never be displayed, but an OK exit-button is needed to keep the error-checker in the resource program happy ** /caption ** Just because a form is included in a resource file doesn't mean it has to ever be displayed. In fact, the form is an excellent organising tool if properly named (names such as "heading" and "code" can cleverly be used to hold window headings and C source code) because it helps develop a self-documenting program. As a bonus, only one rsrc_gaddr() link to the form is necessary, because it contains an easily-addressed "array" of strings. ** CATEGORY.GIF ** ** caption ** Strings organised by function ** /caption ** The drawback is that each string must be separately accessed in your program code when transferring it to the window display routine or the printer routine. Even simple loops used for string copying from the form to the array may break if the form is rearranged and sorted in the resource program. The loop will still work properly, but it will grab the strings in the wrong order and might even try to grab objects which aren't strings. If you do use this loop technique don't ever sort the resource file (there are many sorting methods) and you'll be OK but it's definitely not the recommended way to handle strings. Escape From Bond-age ** STR_COMP.GIF ** ** caption ** TEDINFO Terror: selecting a TEXT object instead of STRING can cause a coding nightmare. Use STRING, not TEXT when building the resource file ** /caption ** When starting a programming project, one of the first tasks is to design the objects for the resource file. Placing all like-minded messages in one form eases the development process, allows for quick examination, and makes future editing easier. The only downside is marginally more tricky programming but this actually provides a self-documenting quality to your work. Why not give it a try and experience the improvement in your coding projects. ** boxout ** Usenet Newsgroup Help is always available online in the Usenet Atari Programming forum, point your news reader at: ** BC ** comp.sys.atari.programmer ** /BC ** If your web browser supports Usenet enter: ** BC ** news:comp.sys.atari.programmer ** /BC ** ** /boxout ** ** boxout ** ** On Reader Disk logo here ** ** R_MOUSE.GIF ** ** caption ** How to detect a right-mouse click ** /caption ** R_MOUSE.PRG demonstrates the right-mouse programming technique. Adventurous developers can use the included H, RSC, and RSM files necessary to change the window display and printer output as desired using ResourceMaster. The C file contains the function that transfers resource strings from the form into the program, and is supplied for easy reference. If you do edit the RSC file remember to work on a backup copy. ** /boxout ** ** boxout ** About the author George Crissman has been a recreational Atari programmer since 1987. His home-brew project is the just-for-fun "Ignoring Standard Interface Techniques" program, an improvement on a password protection program that gives the user "hints" during login. He also apologises to 007 fans for the "Stringways Case". ** /boxout ** ** Images ** ** SORTORDR.GIF ** ** caption ** A rich variety of sorting methods will defeat programmer techniques requiring adjacent objects ** /caption **