Detect changes to controls on forms

Moderator: Rathinagiri

Post Reply
User avatar
RussBaker
Posts: 51
Joined: Wed Jul 22, 2015 9:44 am

Detect changes to controls on forms

Post by RussBaker »

I have a form with many fields and controls.

I would like to have the user notified if changes were made and not saved.
eg: MsgYesNo("Changes not saved. Save them now")

I could use the ONCHANGE property and change a trigger variable.
However I'm looking for a simple way.

--Russ
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Detect changes to controls on forms

Post by andyglezl »

I have a form with many fields and controls.
Maybe you can use:
DEFINE TEXTBOX <Controlname>
PARENT <ParentWindowName>
ROW <nValue>
COL <nValue>
HEIGHT <nHeight>
FIELD <FieldName> // Field of DBF
.....
On CHANGE <WindowName>.<ControlName>.Save

and you forget the message ( you can disturb the user with many posts )
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Detect changes to controls on forms

Post by Rathinagiri »

1. Save the initial values of all the controls in an array.

2. When the user tries to release the window ( on release event) try to check the current values of all the controls and the values in the initial array. If nothing is changed, we can release the window. Otherwise, we can show the message to save.

3. You can use a timer also ( say for every 5 seconds ) to either notify the user to save or automatically save only the changed values.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Detect changes to controls on forms

Post by serge_girard »

Russ,

I agree with Rathi for his points 1 & 2.
It is a bit more complicated but works fine (at least for me!)

Serge
There's nothing you can do that can't be done...
User avatar
RussBaker
Posts: 51
Joined: Wed Jul 22, 2015 9:44 am

Re: Detect changes to controls on forms

Post by RussBaker »

All good solutions. My form is populated with variables from dbf fields scattered to input variables (from old clip code)
During the form INIT I set a variable lChanged to .f.
Then on each field I used the ONCHANGE lChanged:=.t.

When exiting the form, if lChanged=.t. I call my save function.

Simple and works.
Additionally, I used the ONCHANGE to set my original variable to the new value
eg: ONCHANGE (lChanged:=.t., _fname:=myform.fname.value)

I also did this because I couldn't figure out how to make my SAVEVARS() function work with the form value.
Was actually easier because I didn't have to rewrite clip code.

How come this gives me a compiler error?

FUNC SAVEVARS()
REPLACE mydbf->fname with myform.fname.value

So now I use original clip code and rely on ONCHANGE to set the var _fname back to what the VALUE clause was initialized with.
REPLACE mydbf->fname with _fname


--Russ
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Detect changes to controls on forms

Post by serge_girard »

Russ,

Which compile error are you getting?

Serge
There's nothing you can do that can't be done...
User avatar
RussBaker
Posts: 51
Joined: Wed Jul 22, 2015 9:44 am

Re: Detect changes to controls on forms

Post by RussBaker »

serge_girard wrote:Russ,

Which compile error are you getting?

Serge
Line of code is:
replace client->lname with clientinfo.lname.value

clientinfo is my form window name
lname is a text box
client->lname is a character dbf field

Error is:
Harbour: C:\SOURCE\umisc.prg(173) Error E0030 Syntax error Syntax error "syntax error at '.'

I'm a noob at Harbour and don't have much experience here.

--Russ
Carlos Britos
Posts: 245
Joined: Sat Aug 02, 2008 5:03 pm

Re: Detect changes to controls on forms

Post by Carlos Britos »

RussBaker wrote: Line of code is:
replace client->lname with clientinfo.lname.value
Hi try replacing clientinfo.lname.value with GetProperty( "lname", "clientinfo", "value" )
or
xVar := clientinfo.lname.value

replace client->lname with xVar
Regards/Saludos, Carlos (bcd12a)
User avatar
RussBaker
Posts: 51
Joined: Wed Jul 22, 2015 9:44 am

Re: Detect changes to controls on forms

Post by RussBaker »

Carlos Britos wrote:
RussBaker wrote: Line of code is:
replace client->lname with clientinfo.lname.value
Hi try replacing clientinfo.lname.value with GetProperty( "lname", "clientinfo", "value" )
or
xVar := clientinfo.lname.value

replace client->lname with xVar
Thanks for the tips.

What I essentially did was this method
xVar := clientinfo.lname.value

Using the ONCHANGE to set the variable xVar

It appears you cannot replace a dbf field directly with a form value.
User avatar
dragancesu
Posts: 920
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: Detect changes to controls on forms

Post by dragancesu »

Clipper has a function UPDATED(), HMG doing a much better and has control ON CHANGE

My solution to the problem is to after last fields on the screen jumps to the SAVE button and one press ENTER solves the problem
Attachments
test.zip
(14.72 KiB) Downloaded 262 times
Post Reply