Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error in runtimefile but not in developer environment with buffered data

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
In the lostfocus method of textboxes, comboboxes and editbox i have code as down below.
This code resets the fieldstatus if no real change was made during editting record-data.
This works fine in my develop-environment but when running the executable an error pops up saying that that this function requires buffered data.
I am using optimistic rowbuffering.
And to make it more weird. One machine throws this error but another don't.

Any idea?

-Bart

Code:
LPARAMETERS tForm, tObject
LOCAL lcAlias, lcType, lnBufferMode, lnFieldState, lNewRecord, lcOldValue
lcAlias	= ""
lcType  = ""
lnBufferMode = 0
lnFieldState = 0
lNeRewcord = .F.
lcOldValue = ""

WITH tObject
		
	IF VARTYPE(tForm)="O"
		IF PEMSTATUS(tForm,'lNewRecord',5)
			lNewRecord = tForm.lNewRecord
		ENDIF 
	ENDIF 	
	
	IF !EMPTY(.ControlSource) AND ! 'THISFORM' $ UPPER(.ControlSource)
		** voorloopspaties verwijderen
		IF TYPE( .ControlSource )=="C"
			.Value = ALLTRIM(.Value)
		ENDIF
		IF '.' $(.ControlSource)
			lcAlias	= JUSTSTEM(.ControlSource)
		ENDIF
		lcFieldName  = JUSTEXT(.ControlSource)
		
		IF !EMPTY(lcAlias)
			lnSelect = SELECT()
			SELECT (lcAlias)
				lnBuffermode = CURSORGETPROP("Buffering")
				lnFieldState = GETFLDSTATE(lcFieldName,lcAlias) 
			SELECT (lnSelect)
		ELSE 
			lnBuffermode = CURSORGETPROP("Buffering",lcAlias) 
			lnFieldState = GETFLDSTATE(lcFieldName)
		ENDIF 			
		
		IF lnBuffermode > 1
*************
* here the error is triggered
*************
			lcOldValue = OLDVAL(lcFieldName)    
		ENDIF 
		
		DO CASE
		CASE lnBufferMode > 1 AND !lNewRecord AND !EMPTY(lcAlias) AND (lcOldValue = .Value) AND (lnFieldstate = 2 OR lnFieldstate = 4)
			SETFLDSTATE(lcFieldName,ICASE(lnFieldState=4,3,lnFieldState=2,1),lcAlias)

		CASE lnBufferMode > 1 AND !lNewRecord AND  EMPTY(lcAlias) AND (lcOldValue = .Value) AND (lnFieldstate = 2 OR lnFieldstate = 4)
			SETFLDSTATE(lcFieldName,ICASE(lnFieldState=4,3,lnFieldState=2,1))
			
		ENDCASE
	ENDIF

ENDWITH

RETURN
 
for the records
problem is solved by changing piece of code that changes way of lcOldvalue is retrieved

Code:
		IF !EMPTY(lcAlias)
			lnSelect = SELECT()
			SELECT (lcAlias)
				lnBuffermode = CURSORGETPROP("Buffering")
				IF lnBuffermode > 1
					lnFieldState = GETFLDSTATE(lcFieldName,lcAlias)
					lcOldValue = OLDVAL(lcFieldName, lcAlias)
				ENDIF 	
			SELECT (lnSelect)
		ELSE
			lnBuffermode = CURSORGETPROP("Buffering",lcAlias) 
			IF lnBuffermode > 1
				lnFieldState = GETFLDSTATE(lcFieldName)
				lcOldValue = OLDVAL(lcFieldName)
			ENDIF 	
		ENDIF
 
So, the problem was nothing to do with buffering. It was a simple logical error. If the dot was not present in the control source, lcAlias was not getting set, so lnBufferMode was getting incorrectly set. I looked at your original code for quite a long time, but couldn't see that error.

Anyway, glad you've got it working now.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike,
At the end of the day I found this piece of code also caused the disappearing data as dicussed in the other thread...
-Bart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top