Working with Work Areas

Working with Work Areas

* Display the orders for the first one. Author Profile Doug Hennig is a partner with Stonefield Systems Group Inc. loNode = loNodes.item(0) and Stonefield Software Inc. He is the author of the award-win- loOrders = loNode.selectNodes(‘order‘) lcOrders = ‘‘ ning Stonefield Database Toolkit (SDT); the award-winning for each loOrder in loOrders Stonefield Query; the MemberData Editor, Anchor Editor, and lcOrders = lcOrders + ; CursorAdapter and DataEnvironment builders that come with iif(empty(lcOrders), ‘‘, chr(13)) + ; Microsoft Visual FoxPro; and the My namespace and updated loOrder.getAttribute(‘orderid‘) Upsizing Wizard in Sedna. Doug is co-author of the “What’s next loOrder New in Visual FoxPro” series (the latest being “What’s New messagebox(loNode.getAttribute(‘company‘) + ; in Nine”) and “The Hacker’s Guide to Visual FoxPro 7.0.” ‘ has the following orders:‘ + ; He was the technical editor of “The Hacker’s Guide to Visual chr(13) + chr(13) + lcOrders) FoxPro 6.0” and “The Fundamentals.” All of these books are As with generating XML, you can create a from Hentzenwerke Publishing (http://www.hentzenwerke. wrapper class for parsing specific XML. For ex- com). Doug wrote over 100 articles in 10 years for FoxTalk ample, I’ve created a class called SFRSS that parses and has written numerous articles in FoxPro Advisor and Ad- visor Guide. He has spoken at every Microsoft FoxPro De- RSS-formatted XML. The SFXML class I discussed velopers Conference (DevCon) since 1997 and at user groups earlier can parse attribute-based XML without you and developer conferences all over the world. He is one of the having to know XPath syntax; see SFXMLParse. administrators for the VFPX VFP community extensions Web PRG for an example. site (http://www.codeplex.com/VFPX). He has been a Micro- soft Most Valuable Professional (MVP) since 1996. Doug was awarded the 2006 FoxPro Community Lifetime Achievement Summary Award (http://fox.wikis.com/wc.dll?Wiki~FoxProCommunity In this article, I discussed what XML is and pre- LifetimeAchievementAward~VFP). Web: www.stonefield.com sented various methods of generating and parsing and www.stonefieldquery.com, Email: dhennig@stonefield. XML. In the next issue, I’ll discuss why XML is use- com, Blog: http://doughennig.blogspot.com ful and show some practical examples of how I’ve used XML in various applications. Working with Work Areas Tamar E. Granor Although we‘ve had techniques that let us ignore in my head, I started making sure I didn‘t need to work area numbers and letters for many versions, know where a given table was open. some developers still write code that addresses The tools for letting us ignore work areas have work areas directly. This month, I‘ll look at how to gotten better and better over the years. There are write code without worrying about work area let- three related issues. The first is to open a table with- ters or numbers, and how to depend as little as pos- out having to figure out what work area to use. The sible on the currently selected work area. The result second is addressing an open table without know- is better code that‘s easier to write and maintain. ing what work area it‘s in. The third is writing code In dBase II, you could open two tables simul- without having to worry about what work area is taneously. Each occupied one work area. By the current. Combining the three means you‘ll never time I entered the Xbase world with FoxBase+, worry about stepping on an open table or acting on there were 10 work areas; most of the time, that the wrong table again. was enough, but now and then, I found it limiting. FoxPro had 25 work areas in the standard version and 225 with the extended version; I‘m not sure I Use aliases, not work area ever found myself short of work areas, even in the numbers or letters standard version. When VFP shipped with 32,767 Every time you open a table in VFP, the open table work areas per data session, I knew I‘d never worry occupies a work area. As noted above, in VFP (all about available work areas again. versions from 3 to 9), each data session offers 32,767 When there were only two work areas or even work areas. Work areas are numbered from 1 to 10, keeping track of what table was open in which 32,767 (there‘s also a hidden work area 0, used for work area was no problem. But as soon as there system tables, but that‘s a story for another article). were more work areas than I could keep track of The first 10 work areas can also be referenced by the letters A through J. Page 14 FoxRockX July 2008 When you USE a table, by default, it opens in * Version 3 the current work area. If there‘s already a table open USE YourTable IN 0 in that work area, the open table is closed. Once a Similarly, if you specify IN SELECT(1), VFP table is open in a given work area, you can refer to opens the table in the highest available work area, the work area by the alias of the open table. This is like this: always a better approach than using the work area letter or number, since it lets your code express in- * Version 4 tent rather than structure. For example, if you know USE YourTable IN SELECT(1) that the Customers table is open in work area 3, you The difference between the one-line versions 3 can move to that work area with any of the follow- and 4 and the two-line sequences of versions 1 and ing lines of code: 2 is that after the one-liners, you haven‘t changed * Version 1 work areas. You‘re still in the same work area SELECT 3 you were in before opening the table. Often, that doesn‘t matter, especially if you‘re opening a series or: of tables. Consider these two blocks of code: * Version 2 SELECT C * Version 1 SELECT 1 or: USE Customers SELECT 2 * Version 3 USE Orders SELECT Customers SELECT 3 The first two versions tell you very little; to USE OrderDetails understand them, you have to know what table is SELECT 1 open in work area 3/C. The third version, though, * Do something with customer records tells you that you‘re moving to the work area for the Customer table (in fact, there‘s rarely a reason * Version 2 USE Customers IN 0 to select a particular work area anymore; I‘ll talk USE Orders IN 0 about that later in this article). USE OrderDetails IN 0 SELECT Customers Open tables without thinking * Do something with customer records about work areas Not only is version 2 shorter and easier to read, While using the alias rather than the work area but it expresses intent more clearly than version 1. number in your code is handy, it wouldn‘t be all that powerful if you still had to remember which work areas are available every time you wanted Use IN rather than SELECT to open a table. Fortunately, you can avoid that, as With the techniques above, you never have to think well. about work area numbers again, nor keep a chart to show you which table is open in which work area VFP (and FoxPro before it) offers two ways to (I used to do that to ensure I didn‘t make mistakes). find an available work area. SELECT 0 moves to the That‘s a major win, but you can do better. lowest available work area, while the function call SELECT(1) returns the number of the highest avail- Many of VFP‘s commands and functions able work area. You can be sure you‘re opening a operate in the current work area. If you forget to table in an unused work area by issuing either of SELECT the right work area, or you do so but then the following sequences: something changes the work area before your code runs, you can get nasty, unexpected results. For- * Version 1 tunately, many of those commands now accept an SELECT 0 IN clause to indicate which work area to operate USE YourTable on. Similarly, most of the functions accept a param- eter to indicate the work area. or: When you use the IN clause or pass the pa- * Version 2 SELECT SELECT(1) rameter, you ensure that the command or function USE YourTable operates where you want it to; no event, ON KEY LABEL or user action (such as clicking on a grid) In fact, you can consolidate either of those into can switch work areas on you. In addition, you one line of code, with one difference in behavior. don’t need to save the current work area and switch The USE command, like many of VFP‘s Xbase com- to the desired work area, then restore the old work mands, accepts the IN clause to specify the work area after doing whatever you need. area. When you specify IN 0, VFP opens the table in the lowest available work area: July 2008 FoxRockX Page 15 Consider this code: When looking at other people‘s code, I often see lines like this: * Version 1 nOldSelect = SELECT() * Don‘t write code like this SELECT Orders REPLACE Orders.Freight WITH m.nFreightTotal CALCULATE SUM(Freight) TO nTotalFreight If the current work area is Orders, that line behaves as you‘d expect, substituting the value of SELECT (nOldSelect) nFreightTotal into the Freight field of the current Four lines of code to do a simple calculation work area.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us