How to Break out of OK buttons and return to Form

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

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.

Hi Douglas,

Thanks for that tip and help.

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

Regards

Johan de Klerk

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.

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

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.

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

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.

1 Like

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.

1 Like

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.

More related question. I need to complete a Form (so user clicked on OK, save everything) but not close current window but remain on it like I open window again. How I can easy do this?

There a savebutton control template that does just that

was nor clear. I need do that depending from some conditions, not automatic

SaveButton control can still work. You can hide the button when needed or hide it always and just POST an event:accepted to it when needed. I do that in one of my procedures and it works well. Note that takeCompleted is call when the button fires.

1 Like

If you don’t want to check required fields you could try.

Instead of posting an event accepted to the save button you could use a byte field loc:flag and set this to 1 and use:

ReturnValue = PARENT.TakeCloseEvent()

and in this procedure BEFORE
ReturnValue = PARENT.TakeCloseEvent()

IF loc:flag
ReturnValue = PARENT.TakeCompleted()
RETURN Level:Notify
end
!

1 Like