Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Releasing object created with newobject
Message
From
12/05/2003 12:54:52
 
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00787386
Message ID:
00787399
Views:
19
There will be a performance hit each time you create the object. You could create it once and not set it to null immedately after each use. Then in the DESTROY event of you form, set the property to NULL. In your code you would check to see of .oCon is null. If so, create it. If not open it. Something like this:
WITH thisform
        ** only create a reference if it does not exist
        if isnull(.oCon)
	   .oCon = NEWOBJECT('ConMgr','conmgr.prg')
        endif

	.nCon = .oCon.OpenConn('itc_H_drive')
	IF .nCon < 1
		MESSAGEBOX('connection failed')
		RETURN .f.
	ENDIF 
	MESSAGEBOX('connection successful!!!')
	SQLSETPROP(.nCon,"Asynchronous",.f.)
	lnRes = SQLSETPROP( .nCon, "DispWarnings", .F. )
	lcSql = "SELECT UD.SSNo, UD.firstname, UD.middle " ;
	      + "  FROM UDFields UD " ;
	      + " ORDER BY UD.SSNo "
	lnRes = SQLEXEC( .nCon, lcSql, "lcresults" )
	SELECT lcresults
	*BROWSE
	lnRes = .oCon.CloseConn(.nCon)
        ** don't release until DESTROY event of form
	*.oCon = null 
	*RELEASE .oCon
ENDWITH
Then in the DESTROY event of your form put:
This.oCon = null
Put
>Thanks for answering back Dan. I am doing this OOP for firsttime. I have this routine in a command button, Can you think of any problems I might encounter by recreating this object over and over after setting it to null? Should I probably add my property (instead of .oCon) with addproperty using a sys(2015)?
>
>Thanks
>Nick Patel
Thanks,
Dan Jurden
djurden@outlook.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform