Forms and statefulness

I've noticed that forms in WEB Core are not stateful. At least, not in my app when I select a different tab in a Page Control and then return -- the visual controls on the previous page lose any changes that may have been made.

This poses a problem in my case because I'm creating and allocating things to some lists and using content in the controls to know where the user is at in their process, like checklistboxes, grids, multi-selections, treeviews, things in memos, etc. Resetting the visual display like this totally screws-up all of the "work-in-progress" that has already happened.

In this case I'm using an FNC Page Control, but it happens with the regular TWebPageControl as well.

I don't know if this is a "bug" where the Z-order inside of the Page Contols is not being managed correctly, or just another side-effect of dealing with an inherintly stateless canvas. But I need it to work like VCL Page Controls where the contents of a tabsheet don't completely reset if you click on another tab and then come back.

Also, I have some nested page controls so it's not always switching from one tab to another in the same control; it can happen when you go to a sub-tab, then switch tabs to another one in the parent and then go back.

Has anybody else run into this and solved it? If so, what did you do?

I would add some console log statements to the form events, something else is likely causing the refresh.

Just for sanity, I use FNC page controls 3 - 4 levels deep and do not do anything special.

https://swiftexpat.github.io/RunTime-ToolKit/MarshalDemo_Web/MarshalDemo.html

Thanks, I've been digging around in my code and there's nothing I can find that would cause that. In fact, there is a problem in my code where I have trouble restarting things because I'm missing a lot of places where different controls DO need to be cleared and resources freed but they're not yet. The controls on this particular page I'm having trouble with are presently NOT being reset explicitly by anything that I can find. It's a real head scratcher.

The app does mostly flow from one tab to the next, but in this instance, you hit a pause and it goes to the next tab to collect some data, then you click Continue and it goes back.

Strangely, the controls on the tab it goes to when you hit Pause DO retain their state. But hitting Continue takes you back to the previous tab and everything on it has been reset.

hmmm .... it looks like an assignment to the variable tracking the internal state of my app had a typo in it. Grrrrr....

Could you provide a little more context into what the problem was? I can't say I've encountered this before (and I tend to use TWebPageControls quite a lot). Could be that your problem might be something that others run into, though?

It has come up previously which is why I decided to mention it, but in this case there seems to have been an explanation.

Having Bootstrap active, I notice some unexpected things from time to time. I'm starting to recognize some of them. This may be related, but I can't say for sure.

The behaviors of VCL components is very consistent and predictable. But these Web and FNC components ... not so much. I've spent an unexpectedly large amount of time having to find workarounds for things that don't do what they should. In many cases it's because of undefined properties or methods or other things that raise compiler errors. But some are behaviors that just don't work as expected.

For example, I have not been able to get TWebPanels to display a color on them, no matter if I set it at design time or at run-time. Bruno has shown it work in isolation, but I can't get it to work in my form. I tried to use a string grid, but got three different compiler errors that blocked me from going further. Then I tried an FNC Panel and viola! The colors show up!

I guess the Good News is that this little display was an outgrowth of the issue originally mentioned here because I had no way of seeing what the internal state of my app was, so I made something to display it. I settled on something like a trackbar that has 7 segments, each one a different color (think rainbow) and they light up to reflect the internal state. But it took three different approaches to get something that I could have done fairly quickly in VCL. (I could have made them all the same color, but I guess I was excited to finally find something that would show a color at run-time other than clBtnFace.)

Don't get me wrong ... I absolutely LOVE what WEB Core offers. I don't expect it to be free of quirks and glitches, as long as I can find workarounds for dead-ends I encounter. I just seem to be running into a lot of them. The problem is, some are really hard to tell if they're from MY code or the fact that this whole facade is running on top of HTML, CSS, and javascript. Like ... it has taken a while to get used to the fact that if you copy and paste certain things (eg., TWebLabels) where the ElementFont is set to efProperty gets changed back to efCSS when it's pasted, so it doesn't work without changing it back right away. Bruno says it's because of Bootstrap. It makes me wonder how many other things get overridden because of Bootstrap -- especially really complex things like the FNC Page Control.

1 Like

I forgot to mention a case where switching tabs always does a reset: when I have TWebTreeView and some memos (probably TWebMemo), and I switch to another tab and then back, the controls always scroll back to the top. I don't think they're reloading because they retain the state of their contents.

The scrollbar is simply moved up to the top, regardless of where the cursor or selected line is. It's not a problem if there aren't many lines in the control, but if there are, it can be a real nuisance.

There is certainly a learning curve - and a lot more under the covers than we have had to deal with when writing VCL apps. The three amigos, JavaScript, HTML, and CSS, are almost trivial to get started with yet hide some serious complexity and personality that takes a while to get accustomed to, no question.

CSS can be both your best friend and your worst enemy :grinning:

2 Likes

CSS ain't no friend o' mine!