How to Break out of OK buttons and return to Form


#1

Hi,

In my OK (Save) Button I have some embed code to check field values and if wrong I want to cancel the OK (Save) from writing the record and would then like to SELECT(?WrongField) and stay on the form.

Any one got some advice on how to do this please?

Using Clarion 6.3-9058.

Regards

Johan de Klerk


#2

Move your code from the Ok button to the WindowManagerClass.TakeCompleted method before parent call.
Return an appropriate value after reading the docs for the method.


#3

Hi Douglas,

Thanks for that tip and help.

I think I have it working now, so far so good.

Regards

Johan de Klerk


#4

Ont tiny thing to add to what totalhip said. in ThisWindow.TakeCompleted, before the parent call, you can CYCLE to let the method handle returning LEVEL:Notify which is what you want. Or you can just RETURN LEVEL:Notify yourself. I like using CYCLE because I think it’s neater but it’s personal preference.


#5

Hi Peter,

At this stage I am using: RETURN Level:Notify.
It works at this stage.
I have never used this Embed so this is new to me.

Would you say that a CYCLE is a better option than Level:Notify?

Always looking for the best possible options.

Regards

Johan de Klerk


#6

I don’t think it is good coding practice to RETURN from inside a LOOP but the embed points for ThisWindow.TakeCompleted (and lots of others), are inside a LOOP. Using CYCLE causes the code to issue its own RETURN LEVEL:Notify from inside the loop but I can pretend that at least I am not doing it. If I were coding WindowManager.TakeCompleted, I would have done without the loop or used a flag field (as they used Looped) to indicate success or failure of the code. Then in the embed, I could set the flag the way I wanted and issued a BREAK then tested the value of my flag below the loop to determine what value to RETURN. I am just picky and in your case, issuing RETURN LEVEL:Notify directly is really equivalent to CYCLE.


#7

Hi Peter,

Thank you very much for the detailed explanation.
I now understand this Embed a lot better.

I will be going with your suggestion and use CYCLE.

PS: I wished I knew about this Embed long time ago then much of my code would have been better, but this is how we learn.
This embed is going to solve a lot of my problems.
Have lots of forms where I will be implementing this.

Regards

Johan de Klerk


#8

Hi Peter - Don’t tell that to the ABC classes, then. :slight_smile:

Open up ABWINDOW.CLW and there are occurrences of returning inside a LOOP.


#9

Hi Johan -

If you try to lose the “which embed” mentality and look at what the underlying code does, it will greatly enhance your understanding of what’s going on, not to mention your productivity. I find it useful to open up the source classes and see what calls what. (I use Ctrl+F a lot)
ABC can definitely seem like voodoo at first, which makes stuff feel unattainable, but it’s really not so bad.


#10

Another reason to use the TakeCompleted method embeds is that the TakeAccepted embed for the ?Ok button is not fired if the user closes the window then opts to save when prompted by the ABC class. The TakeCompleted method, however, does.

On forms, I use the embed BEFORE the parent call to check that the user has completed things properly and to set some hidden fields that must be set based on the main file fields.

I use the embed AFTER the parent call to test IF ReturnValue = LEVEL:Benign then do any child or related record processing based on changes to the form’s primary file.