Determining if something on a form has changed

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Determining if something on a form has changed

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:43 am

by Peter Smith >> Thu, 5 Aug 1999 5:11:59 GMT

What Im after is an easy way to determine that something has changed on a form so that I can check at an appropriaet time eg on form close and throw up a dialog box to give the user the chance to save etc
Seems from looking around that there are 2 or 3 main ways to do this.

1/ subclass all controls and then put code in the change event to set a boolean on the parent
form.

2/ Create a string of 'data' from the controls on the form at the start when data is loaded and then again at the end and compare them. Problem I have here is that there is no practical way to generate this that is foolproof - and so the list of controls will need to be manually maintained. Tables and listboxes used in differnet ways mean that its difficult to build the string generically.

3/ Use event mappings sso as to set the change event for all textboxes to your own method. Drawback here is that then you take away the change event for all controls and in some cases you may want it.

Appreciate any thoughts/ideas on this - as all the ways mentioned above have drawbacks.


b

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Determining if something on a form has changed

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:43 am

by Roger Parkinson >> Tue, 10 Aug 1999 7:06:57 GMT

Use (2). You can use meta data do work through all the controls. Hang a method on each control you use to get the data back as a string and concatenate them all as you work through. Of course writing the methods probably means you end up subclassing the controls so you might as well use (1), but comparing the strings as in (2) means that if they change a value and then change it back again your test will detect no changes, which is smarter.

You can take some shortcuts by implementing the change event and have it set an attribute to some 'changed' value. Your getCurrentValue() method can just return the flag. This saves generating a potentially huge compare string on table data, although you lose the changed/changed back advantage.

Don't use (3) it's too much work.

Roger

Some controls (especially tables) you can just sub


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 40 guests