In one of my previous posts on “how to link a faxbox in code“, I explain .. uhm .. how you can link a faxbox in code.. (you might have guessed that). Now, one of the things you have to keep in mind (as a programmer) when doing so, is the fact that the code on your “OnAfterGetCurrRecord” of your page is always executed. So if you’re putting code there to update your factbox, it’s also going to (try to) execute it, even when it’s not visible. You don’t want that.
So how do I fix this?
Well, it would be nice to be able to use something like this, isn’t it?
IF NOT CurrPage.MyFactBox.PAGE.VISIBLE THEN …;
Let’s save you the trouble .. you can’t! At least not out-of-the-box..
So why just not creating that property ourselves on our own factbox?
Is that possible?
Well, with PRS, we try to let people think in an (and I should be careful which words I use .. but I’m still gonna .. blame me for it..) “Object Oriented” way. So if the Factbox is my object, I want to add the “Visibility”-property on it!
This is how I did it (or at least tried to do it).
First of all, I declared a global boolean on the factbox, which I call “PageIsVisible“.
Now, you want to be able to call this boolean from outside, so you create a global function on your factbox “IsVisible“, like:
IsVisible() : Boolean
Last thing, to “set” your boolean, I rely on the fact that, when you set your factbox visible, the code runs through the “OnOpenPage” trigger. I think it’s quite safe to rely on.. , So, all you do is:
PageIsVisible := TRUE;
It’s as simple as that!
Now you can use this function in your form where you use your page where you wanted to show the factbox, like this:
IF NOT CurrPage.VMFMessageFactbox.PAGE.IsVisible THEN EXIT;
With the new debugger, you can easily see if it works .. as you see below, where I set a breakpoint in the IsVisible-function on my factbox. As you can see, the boolean is false, which was correct.. as my factbox was indeed not visible at that time..
There were a few people who reminded me to write this blog .. so hope this answers the question .. and help them with their situation.
If not .. or you’ve got remarkt .. I’m always happy to get comments!