Viewmod(0) and Internal Close Event


Dave Beckinsale
 

Hi Group,

I've an SDI form in XPA 4.7.2 which is using Viewmod to determine if the user has changed any values

It's working ok, but I've noticed if I stay on the modified field and just hit the close X icon at the top of the form window and not use the close form button, it closes without asking if i want to save the changes.

I've just used an editget() on one of the fields as a test as part of an internal close event and this then works but I wondered if there was a better way of doing this that I've missed.

Many thanks
Dave.   


Wes Hein
 

From Help file:///C:/XPA_4.81/Help/mergedProjects/MGHELPW/Differences_Between_V1.9_and_Magic_xpa_2.5.htm?rhhlterm=viewmod&rhsyns=%20
  • In the previous Online version, some functions, such as InTrans and ViewMod, were always re-evaluated, even if there was no variable in the expression. This behavior was changed and the expression that contains functions is now re-evaluated only if the expression has a variable that was changed. 

    You can reproduce the previous behavior as follows:

    1. Add a Virtual variable (with Part of dataview=No) to the program.

    2. Update the variable in the Record Prefix with False.

    3. For ViewMod() – Add a handler on an Expression event with the following condition: ViewMod(0) AND A<>ViewMod(0)  [where A is the variable]

      In the handler, update the variable with ViewMod(0).

    4. For InTrans() – Add a handler on the Control Modify internal event

      In the handler, update the variable with InTrans().

      That's it. Now the variable is updated accordingly and can be used on the form.


Dave Beckinsale
 

Hi Wes,

Thanks for the reply.

I've added that to the program but it still allows me to close clicking x at the top right of the form if I don't move away from the modified field.  If I do move onto the next field and click to close the form then it seems to register that I've changed a field value and I get a prompt to save changes. 

I can get this to work, if within part of the internal close event I update all the fields on the form with editget() but should i need to do this or is there a better way ?

Thanks again.

Dave.


Wes Hein
 

Try using the Control Modify event to update a virtual as true with  (then reset the virtual as false in the record prefix) it should catch it.

Wes


Dave Beckinsale
 

Hi Wes,

Thank you for the suggestion, you are correct, that does resolve the issue in as far as I now get the save message when I change a field.on the form but don't move off and just hit close which is great.

The only difference I can see now, is if the user changes the field but over types with the same value, previously viewmod knew the value hadn't changed and wouldn't ask to save but now it does.

I think this is acceptable, so will proceed with your example.

Thanks again for your help

best regards
Dave.


Thomas Titus
 

What you want is to update the variable value after you hit Escape, Close(X) or button with internal event Exit so that you can evaluate status ViewMod(0).

1. You need to trap the internal event Exit. Create a user event "Verify ViewMod" with Trigger Type None and Force Exit Editing.
2. Create virtual variable vIsOkToExit of type Logic, Part of View=No and INIT with expression 'FALSE'Log.

3. Trap the internal event Exit and raise the user event "Verify ViewMod" that force exit of edit mode to save the field value in to the variable. This allows you to return the correct value of the function ViewMod(0).

4. Once you have verified the ViewMod(0) then you can make appropriate action.

Thomas Titus

 

 


Dave Beckinsale
 

Thanks Thomas for taking the time to explain this.

 

Works Perfectly!!!

 

Best regards

Dave