VectorGeek Posted September 6, 2018 Share Posted September 6, 2018 Hey y'all: We have a custom Path PIO that we use to track various areas (unit overall, storage, balcony) for apartment units. So that I can create a database worksheet that summarizes all the areas, unit by unit, I am working on a command that posts the areas from two small path polys to a larger path poly. The user would run this command before recalculating the database worksheet. I'm using a few ForEachObject() procedures (one in the main procedure, and two in a subroutine) to cycle through the objects, looking for a match by "unit number". Here is the code: Procedure bindareas; VAR h : HANDLE; hProcessStorage, hProcessBalcony : HANDLE; TheUnitNumber, StorageArea, BalconyArea : STRING; Procedure process_storage (hProcessStorage : HANDLE); BEGIN IF GetRField(hProcessStorage,'VG-Area Poly','unitnumber') = TheUnitNumber THEN BEGIN {get the storage area and post it to the source object} StorageArea := GetRField(hProcessStorage,'VG-Area Poly','calculatedarea'); SetRField(h,'VG-Area Poly','boundstorage', StorageArea); END; END; Procedure process_balcony (hProcessBalcony : HANDLE); BEGIN IF GetRField(hProcessBalcony,'VG-Area Poly','unitnumber') = TheUnitNumber THEN BEGIN {get the balcony area and post it to the source object} BalconyArea := GetRField(hProcessBalcony,'VG-Area Poly','calculatedarea'); SetRField(h,'VG-Area Poly','boundbalcony', BalconyArea); END; END; Procedure do_me (h : HANDLE); BEGIN TheUnitNumber := GetRField(h,'VG-Area Poly','unitnumber'); ForEachObject(process_storage,((NOTINDLVP & NOTINREFDLVP & (R IN ['VG-Area Poly']) & ('VG-Area Poly'.'polyclass'='Area-Storage')))); ForEachObject(process_balcony,((NOTINDLVP & NOTINREFDLVP & (R IN ['VG-Area Poly']) & ('VG-Area Poly'.'polyclass'='Area-Balcony Open')))); END; BEGIN {main} ForEachObject(do_me,((NOTINDLVP & NOTINREFDLVP & (R IN ['VG-Area Poly']) & ('VG-Area Poly'.'polyclass'='Area-Strata')))); ResetObject(h); END; Run(bindareas); When I run it, it works, except for the posting of values to the main Path PIOs (the SetRField() procedures). In the subroutines “process_storage” and “process_balcony”, I am getting an error in the debugger that the handle called “h” is NIL so it doesn't execute the SetRField() routine. I don’t really understand passing handles to subroutines very well so I think it’s probably something simple. Any help would be greatly appreciated. All the best, V-G Quote Link to comment
Nicolas Goutte Posted September 6, 2018 Share Posted September 6, 2018 (edited) You are not setting the variable "h" as defined by VAR h : HANDLE; in the main procedure. Procedure do_me (h : HANDLE); only sets "h" in that function. It is by chance the same name as the "h" variable of the main procedure but it is not the same variable. Edited September 6, 2018 by Nicolas Goutte Quote Link to comment
VectorGeek Posted September 6, 2018 Author Share Posted September 6, 2018 Thanks Nicolas - I'm still confused however. If I declare h:HANDLE in the main procedure, isn't it available throughout the entire script? How would you recommend that I setup the handles in the sub-procedures then? V-G Quote Link to comment
Nicolas Goutte Posted September 6, 2018 Share Posted September 6, 2018 It is available, but as you do not set it, it has a default value that is NIL. May be you can try something like: Procedure do_me (myH : HANDLE); BEGIN h := myH; TheUnitNumber := GetRField(h,'VG-Area Poly','unitnumber'); ForEachObject(process_storage,((NOTINDLVP & NOTINREFDLVP & (R IN ['VG-Area Poly']) & ('VG-Area Poly'.'polyclass'='Area-Storage')))); ForEachObject(process_balcony,((NOTINDLVP & NOTINREFDLVP & (R IN ['VG-Area Poly']) & ('VG-Area Poly'.'polyclass'='Area-Balcony Open')))); END; Quote Link to comment
JBenghiat Posted September 6, 2018 Share Posted September 6, 2018 I think the score of variables with the same name is confusing. You have h defined as a global variable. Do_me also defines h, which is local for do_me and takes precedence— the arguments in a function definition are essentially like a VAR block for that function. If you rename your global as gH, and in do_me set gH := h, you may be good. You also may want to restructure your script a bit to make calculated area a global and add an & statement to the do_me FEO criteria so you also only search for object matching the unit number. Quote Link to comment
Nicolas Goutte Posted September 6, 2018 Share Posted September 6, 2018 (edited) May be the problem is another one: what means the variable h in the main procedure for you? Why do you want to reset only one object by ResetObject(h); ? Are you missing to set h to the first selected object (or similar)? Edited September 6, 2018 by Nicolas Goutte Quote Link to comment
VectorGeek Posted September 6, 2018 Author Share Posted September 6, 2018 Many many thanks Nicolas and Josh. The assigning of the global variable "h" to a new variable works perfectly! V-G. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.