I.T. Discussion Community!
-Collapse +Expand
Paradox
Search Paradox Group:

Advanced
-Collapse +Expand Paradox To/From
To/FromCODEGuides
-Collapse +Expand Paradox Store
PRESTWOODSTORE

Prestwood eMagazine

August Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyCorel Paradox / ObjectPAL Coding BoardObjectPAL Topic   Print This     

Closing TCursor variables declared within a method

Closing TCursor variables declared within a method in ObjectPAL topic (part of our Corel Paradox / ObjectPAL Coding group).

Quick Search: Closing   TCursor   variables   declared   Closing TCursor   Closing TCursor variables   declared within  
objectpal123

If a variable that is declared within a method goes out of scope at the end of that method, is it really necessary to close a TCursor variable that is declared within a method?

 Posted 10 months ago (Thread Starter)
Comment Quote
About objectpal123 -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #17282, 9 replies
Thread Started 10/8/2018 6:06:49 PM
View Counter=681
Last Reply Posted 10/12/2018 9:00:33 AM)
Location= 
Joined=13 years ago   MB Posts=4  
Moderator
Steven.G
Myrtle Beach, SC USA

yes.. every open tcursor is an open lock on that table

Steven Green
Senior Software Engineer
Paradox Support Specialist DOS/WIN

Prestwood IT Solutions
8421 Auburn Blvd, Suite 256, Citrus Heights, CA 95610
Office: 916-726-5675 | Fax: 916-726-5676 | http://www.prestwood.com
 Posted 10 months ago
Comment Quote
About Steven.G -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #17283 (Level 2) and Parent is 17282
Reply Posted 10/8/2018 6:26:46 PM
Location=Myrtle Beach, SC USA 
Joined=35 months ago   MB Posts=300  
objectpal123

Since open locks on a table have no relevance in a single user application, can such applications disregard the closure of TCursor variables declared within a method?

 Posted 10 months ago (Thread Starter)
Comment Quote
About objectpal123 -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #17284 (Level 3) and Parent is 17282
Reply Posted 10/8/2018 9:22:07 PM
Location= 
Joined=13 years ago   MB Posts=4  
Moderator
Steven.G
Myrtle Beach, SC USA

I've been making a wonderful living, the last twenty years or so, fixing and upgrading apps that were built on that assumption

as with anything else in life, if it's worth doing, it's worth doing right

how much effort is required to type "tc.close()" ??

Steven Green
Senior Software Engineer
Paradox Support Specialist DOS/WIN

Prestwood IT Solutions
8421 Auburn Blvd, Suite 256, Citrus Heights, CA 95610
Office: 916-726-5675 | Fax: 916-726-5676 | http://www.prestwood.com
 Posted 10 months ago
Comment Quote
About Steven.G -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #17285 (Level 4) and Parent is 17282
Reply Posted 10/9/2018 5:03:35 AM
Location=Myrtle Beach, SC USA 
Joined=35 months ago   MB Posts=300  
rum
Frankfort, KY USA

My mother used to tell me

"If you open the refrigerator door,  then you must close the refrigerator door"

She didn't know she was teaching me one of the basic rules of coding. 

"if you open it, you must close it"

 Posted 10 months ago
Comment Quote
About rum -Collapse +Expand
Visit Profile
Membership pending.
Member subscribes to this thread with a verified email.
Member pending approval.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #17286 (Level 5) and Parent is 17282
Reply Posted 10/9/2018 6:09:21 AM
Location=Frankfort, KY USA 
Joined=26 months ago   MB Posts=88  
objectpal123

Your comments have made me understand why any ObjectPAL coding that I might do in the future should certainly follow your advice.  However, I have been writing an application which includes a number of methods that each execute as many as 20 return statements before a local tcursor variable had been closed (which is contrary to your advice).  To fix this I would need to modify each of those methods in the following manner...

1.    Put all of my ObjectPAL statements inside the transaction block of a try...onFail block.


2.    Replace all of the return statements in the transaction block with fail statements.


3.    Put the following code inside the recovery block of the try...onFail block:

        if tc.isAssigned() then
            if not tc.close() then
                msgStop(self.name+"::method name", "not tc.close()")
            endIf
        endIf

4.    The method should only include one return statement and it should be executed at the end of the method.

As each of these methods has as many as 340 lines of code such modifications do not seem warranted in light of the facts that the code seems to be working properly, I have checked it for errors, it is a single user application written only for myself and probably won't be used more than once.  But this conclusion would depend on the answer to my last question which sought to ascertain whether a single user application can disregard the closure of TCursor variables declared within a method, since open locks on a table seem to have no relevance in a single user application.

 Posted 10 months ago (Thread Starter)
Comment Quote
About objectpal123 -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #17287 (Level 6) and Parent is 17282
Reply Posted 10/9/2018 3:37:37 PM
Location= 
Joined=13 years ago   MB Posts=4  
Moderator
Steven.G
Myrtle Beach, SC USA

> ut this conclusion would depend on the answer to my last question which sought to ascertain whether a single user application can disregard the closure of TCursor variables declared within a method, since open locks on a table seem to have no relevance in a single user application.

technically, correct.. and if it breaks, you're the one who fixes it, so also correct

and, you learned something generic, for when you need it later, on this app, or any platform.. clean up behind yourself :-)

Steven Green
Senior Software Engineer
Paradox Support Specialist DOS/WIN

Prestwood IT Solutions
8421 Auburn Blvd, Suite 256, Citrus Heights, CA 95610
Office: 916-726-5675 | Fax: 916-726-5676 | http://www.prestwood.com
 Posted 10 months ago
Comment Quote
About Steven.G -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #17288 (Level 7) and Parent is 17282
Reply Posted 10/9/2018 4:38:56 PM
Location=Myrtle Beach, SC USA 
Joined=35 months ago   MB Posts=300  
Moderator
Steven.G
Myrtle Beach, SC USA

and, FWIW.. because it's way easier for "the next guy" to read, in the stuff I inherit from others, and fix along the way.. I just do like this, step by step

if not whatever() then

   tc.close()

   return

endif

if not theNextThing() then

  tc2.close()

  tc.close()

  return

endif

etc, etc.. it's way easier to read than 40 imbedded if's

Steven Green
Senior Software Engineer
Paradox Support Specialist DOS/WIN

Prestwood IT Solutions
8421 Auburn Blvd, Suite 256, Citrus Heights, CA 95610
Office: 916-726-5675 | Fax: 916-726-5676 | http://www.prestwood.com
 Posted 10 months ago
Comment Quote
About Steven.G -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #17289 (Level 8) and Parent is 17282
Reply Posted 10/9/2018 4:40:43 PM
Location=Myrtle Beach, SC USA 
Joined=35 months ago   MB Posts=300  
objectpal123

When you said "technically, correct", you seem to be suggesting that the failure to close TCursor variables declared within a method will not cause any harm as long as that application is not used in a multiuser environment.  However, your language after that comment seems to suggest that such code might break.  If the application is never used in a multiuser environment, why would it break?

 Posted 10 months ago (Thread Starter)
Comment Quote
About objectpal123 -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #17295 (Level 9) and Parent is 17282
Reply Posted 10/12/2018 8:26:39 AM
Location= 
Joined=13 years ago   MB Posts=4  
Most Recent Post
Moderator
Steven.G
Myrtle Beach, SC USA

my job is to teach "best practice".. and allow for when it's not always worth re-engineering for, like in this situation.. your mileage may vary :-)

Steven Green
Senior Software Engineer
Paradox Support Specialist DOS/WIN

Prestwood IT Solutions
8421 Auburn Blvd, Suite 256, Citrus Heights, CA 95610
Office: 916-726-5675 | Fax: 916-726-5676 | http://www.prestwood.com
 Posted 10 months ago
Comment Quote
About Steven.G -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #17296 (Level 10) and Parent is 17282
Reply Posted 10/12/2018 8:58:36 AM
Location=Myrtle Beach, SC USA 
Joined=35 months ago   MB Posts=300  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1251A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #17282 Counter
681
Since 10/8/2018
Follow PrestwoodBoards on: 


©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech