das@eplunix.UUCP (David Steffens) (03/01/90)
My question concerns proper use of the QuickDraw CloseRgn call. According to my reading of _Inside Macintosh_ Volume I, pages 181-183, the following Pascal program fragment should always work correctly: RH:RgnHandle; for i:=1 to 100 do begin RH:=NewRgn; OpenRgn; { draw something } CloseRgn(RH); { do something with the region } DisposeRgn(RH) end The description of SetEmptyRgn on page I-183 seems to imply that the same function can be performed with one less call in the loop: RH:RgnHandle; RH:=NewRgn; for i:=1 to 100 do begin SetEmptyRgn(RH); OpenRgn; { draw something } CloseRgn(RH); { do something with the region } end; DisposeRgn(RH) Depending how the description of CloseRgn is interpreted, however, it seems reasonable to conclude that old region data, if any, is first thrown away before the new region data is installed. If true, the call to SetEmptyRgn seems unnecessary, and the number of calls in the loop can be minimized while still maintaining correct behavior: RH:RgnHandle; RH:=NewRgn; for i:=1 to 100 do begin OpenRgn; { draw something } CloseRgn(RH); { do something with the region } end; DisposeRgn(RH) I'm not loooking for an answer like: "Yeah, I tried it and it works." I already did, and it does. The real question here is -- can I afford to bet the farm on it _always_ working? Can anyone provide a definitive answer? -- {harvard,mit-eddie,think}!eplunix!das David Allan Steffens 243 Charles St., Boston, MA 02114 Eaton-Peabody Laboratory (617) 573-3748 (1400-1900h EST) Mass. Eye & Ear Infirmary
ccc_ldo@waikato.ac.nz (Lawrence D'Oliveiro) (03/01/90)
If I may quote from the Old Testament, page I-182: "CloseRgn does *not* create the destination region: space must already have been allocated for it." In other words, CloseRgn acts like every other call that takes one or more region arguments: you've got to allocate the regions first, using NewRgn, and dispose of them after use, with DisposeRgn. In other words--yes, your code will always work.