Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Endless loop - need a hand to get out
Message
 
 
À
02/10/2002 08:44:12
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00706602
Message ID:
00706840
Vues:
26
>>Hi everybody,
>>
>>Ok, now after I explained my frustration I hope to get some help on the following problem:
>>
>>I have a grid on a form to type additional mortgage info. E.g. each main sale/mortgage record may have up to 5 additional mortgage records.
>>
>>In the grid I have a method to validate user's entry. Some code is in BeforeRowColChange, AfterRowColChange, textbox.Valid, Valid method of the grid, etc.
>>
>>Everything seems to be working now except for the following:
>>
>>I have a validation, that if Lender is not empty, Mortgage should be not empty too. In addition, user must re-type Amount using separate form.
>>
>>Now this is that happening: I type amount, re-type it, then click in a control on a page (outside of the grid). I get a message, that Amount could not be empty if Lender is not empty. It looks like the Valid of the grid fires before the valid of grid's column textbox fires, e.g. the value, I typed, have not been written to the table yet, therefore this message is issued.
>>
>>How should I fix this problem? I suppose, in Grid's Valid event I have to ensure, that valid of ActiveColumn textbox already fired... Can you give me a hint, please?
>>
>>My manager just came and said, that DataEntry is my first priority, sorry...
>>
>>Oh, well...
>
>I usually postpone validation until changes are saved. I think lots of trouble can be avoided that way.
>
>Hilmar.

The definition of the problem required validation to be fired immediatelly in addition to validation while saving.

Anyway, I just solved this problem using code, generously provided by Vlad. I put the following code in ValidateGrid method:
********************************************************************
*  Description.......: ValidateGrid - validates MortgGrid on Sales and Mortgage pages
*  Calling Samples...:
*  Parameter List....: tcTable, toGrid
*  Created by........: Nadya Nosonovsky 07/25/2002 02:57:47 PM
*  Modified by.......: Nadya Nosonovsky 10/01/2002 12:47:12 PM
********************************************************************
lparameter tcTable, toGrid
local llReturn, lnSelect
lnSelect = select()
llReturn = .t.
with thisform
	if not .CancelValidation()
*!*	* code from  06/06/2002 Vlad Grynchyshyn
		local oObj
		oObj = .activecontrol
		if vartype(m.oObj) == "O"
			if PEMSTATUS(m.oObj,"DoValid",5)
				m.oObj.DoValid = .f. && Don't want to fire validation
			endif

&& If it's a grid, we need to calculate the active control

			if upper(m.oObj.baseclass) == "GRID"
				nIndex = m.oObj.activecolumn
				for i=1 to m.oObj.columncount
					if m.oObj.columns(i).columnorder = m.nIndex
						nIndex = m.i
						exit
					endif
				endfor
				oObj = m.oObj.columns(nIndex)
				oObj = evaluate("m.oObj." + m.oObj.currentcontrol)
			endif

*!*	&& Check if control has different value than its ControlSource
			if !(m.oObj.value==evaluate(m.oObj.controlsource))
**oObj.setfocus && This is enough to write changes into ControlSource
				m.oObj.value = m.oObj.value && Updated:NN: 06/07/02
			endif
		endif
		select (m.tcTable)
		scatter name oBlank blank
		scatter name oCheck
		if compobj(oBlank, oCheck) && It's a completely blank record - don't validate it
		else

			llReturn = .MortgageValid(evaluate(m.tcTable+'.mortgage'), ;
				evaluate(m.tcTable+".Lender"), 0,'M' )
			if not m.llReturn
				if empty(evaluate(m.tcTable+".Lender"))
** Set focus to the Lender column
					toGrid.colLender.setfocus()
				else
** Set focus to the Mortgage column
					toGrid.colMortgage.setfocus()
				endif
			endif

			if m.llReturn
				llReturn = .ValidateLender(evaluate(m.tcTable+'.Lender'), ;
				                           evaluate(m.tcTable+".LName"))
				if not m.llReturn
					toGrid.colLender.setfocus()
				endif
			endif

			if m.llReturn
				llReturn = .BookPageValid(evaluate(m.tcTable+'.Book'), ;
				                          evaluate(m.tcTable+'.page'), ;
					evaluate(m.tcTable+'.DocketRef'),' ')
				if not m.llReturn
					toGrid.colPage.setfocus()
				endif
			endif
		endif
		select (m.lnSelect) && Return back
	endif
endwith

return m.llReturn
Now it works as I desired.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform