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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changes Made Or Not ? 2

Status
Not open for further replies.

FreddyHo

IS-IT--Management
Jul 2, 2001
20
0
0
HK
I'm trying to write a code to check whether changes had been made to a field (in a table (with BufferModeOverride =5 set in DataEnvironment). The purpose is to remind user to save data before quiting the program if changes'd been made. I'm using the function GetFldState() but it always return me a value "2"(=field has been modified) even though I didn't change the value at all. What I've done is just clicking on the textbox which has CursorSource connected with that field.

What shall I do to get it right? Pls help!
 
GETFLDSTATE() should only return 2 if the field has actually changed. Just clicking in it shouldn't do that. Is is possible you've got some code in the field's Click, or Valid, or LostFocus, that might be causing the control source to be updated?

For what it's worth, the way I check for "dirty" data is like like this:

IF GETNEXTMODIFIED(0, Somealias) <> 0
* At least one record has been modified
ENDIF

That will work for table buffering. An alternative would be to compare the field's CURVAL() with its OLDVAL().

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
>> I'm using the function GetFldState() but it always return me a value "2"(=field has been modified) even though I didn't change the value at all. What I've done is just clicking on the textbox which has CursorSource connected with that field.


I agree with Mike, this is not default VFP behavior so there must be some code somewhere in the textbox class that is causing the value to be updated.

Note that GetFldState() does NOT tell you that a value has been changed, merely that the field has been updated! In other words code in the Textbox Valid that does something like this:

This.Value = This.Value

is enough to flag the field as "changed".



----
Andy Kramek
Visual FoxPro MVP
 
Yes, it is the valid event that matters. I write codes to pad the value to the left. Once I remove it, it works perfectly. (Then I have to think how to pad the value to the left).

Heartful thanks to Mike & Andy.
 
In a small form with only a few fields I put a database field validation rule in each field of the table that calls a procedure in the database container to check if the value was changed, if so, set a public variable, and when leaving the form conditionally committed the changes without the user clicking save. The code was a bit clumsey but with only a few fields is worked well and avoided the save button all together.
wjwjr

This old world keeps spinning round - It's a wonder tall trees ain't layin' down
 
Freddy,

Then I have to think how to pad the value to the left

What exactly do you want to achieve? Is this a numeric field, and you want to right-justify it? If so, it should be possible to do that with the InputMask property.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

It is a text field and I just to make sure to record the proper value especially some users may mistakably type some spaces (usually pressing spacebar) before the proper value. For example, one originally want to input "ABC" i/o " ABC". And I just want to trim all leading space (previously in valid event). Any hint?
 
>>For example, one originally want to input "ABC" i/o " ABC". And I just want to trim all leading space (previously in valid event). Any hint?

The issue is that, as I said, any change you make to the field's value will cause VFP to see this as changed.

One option is to add a property to the text box class (name it uOldVal) and then in the GotFocus() save the current value to uOldVal. Now, in the Valid you can check to see if the current value = original value and, if there is no substative change you can use SetFldState() to clear the change flag for the field. Code like this:

Code:
TextBox::GotFocus
This.uOldVal = This.Value

TextBox::Valid
IF NOT ALLTRIM( This.Value ) == ALLTRIM( This.uOldVal )
  *** This really is a change
ELSE
  *** No substantive change, just tidy up in case
  This.Value = ALLTRIM( This.Value )
  SETFLDSTATE( [field_name], 1, [table]
ENDIF
Note that you cannot use SETFLDSTATE() to make an append look like a deletion, or vice versa. In other words you can only swap 1/2 or 3/4!


----
Andy Kramek
Visual FoxPro MVP
 
I got exactly what I want now with hints from Mike & Andy. Thanks & credit to you both!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top