One of the big omissions IMO in Anvil is the lack of a comprehensive set of data entry fields. By field I mean a combination of a prompt, a entryfield (like the standard textbox, a dropdown, etc), a helpline. This combined with field level plus form level validation. So maybe masks or rules as well. See https://quasar.dev/vue-components/input for just one example.
I think data entry fields would be a big productivity boost.
So I set about to create some simple Fields myself. This was not easy. Every component duplicated a lot of code. The usual approach would be to create an abstract EntryField and derive other fields from this one.
However I could not get inheritance to work for Form components (and their Templates). Is it even possible?
(PS for anyone interested, I ended up creating some standard components in combination with the form validation library mentioned above. Not very elegant but it works; I think
Yes that should work, I think.
I was messing with one Form component derived from another. That was a bit too confusing for me.
Your approach would at least get the common functionality in one non-visual class.
I know. It’s just that I don’t know how the FormTemplate inheritance (if any) would work.
Say I have a composite form consisting of a prompt label, a help text label, an error label (which is what all fields would have in common). Could a derived FormTemplate inherit these comps and add, say, a text box. I wouldn’t know how ATM.
There are hundreds of examples of Anvil Forms using other Forms by composition. While I’ve seen C++ Builder Forms using other C++ Builder Forms by inheritance (and even built a few dozen), I don’t recall seeing it in Anvil.
Part of that may be the way the auto-generated base classes (FormTemplates) behave. I doubt that they were built with that style of inheritance in mind. C++ Builder forms do not have such intermediary base classes, which could easily get tripped up by another Form higher in the class hierarchy.
If Anvil officially supports the kind of inheritance you have in mind, I’d go for it. Otherwise, I’d reuse Forms by composition, not inheritance.