Form Inheritance
Last updated
Last updated
Form inheritance is used to extend a form's functions and UI with those of another form (the super form). This will give the original form all the methods/variables/elements/properties/parts of the form that it extends.
The inheritance is not limited to 1 level, for example there is a form a, form b and form c, form b is extended with a and c with b. The result is that form c will then have all the methods/variables/elements/properties/parts of form a, b and c.
When using form inheritance, the properties and methods can still be overwritten in the sub forms. This is not the case for the datasource, the datasource can not be changed from one table to another, it can be changed from empty to a table.
Let's consider the following main forms:
Form base_code
: Here are all the functions like 'new record', 'delete record' and all buttons found in base
form. On this form there are no parts, it is strictly code. This form will have no datasource.
Form base
: Here are buttons for 'home', 'settings', 'employees', 'save', 'cancel' . There could be more than one, so there can be multiple designs. This form will inherit the base_code
form and uses all it's functions. This form will have no datasource.
Sub forms, which extend base
form and will inherit the base
form (because the functions and buttons are already inherited only the datasource and fields have to be added) :
Form home
Form settings
Form employees
Form new_employee
The parent form (super form) can be set by selecting its form name in the subform's extendsForm property.
Inherited form properties can be overriden in the subform's properties.
Inherited form event bindings can be overriden in the subform's scripting editor. This can also be completely removed from the subform.
Inherited component's properties can be overriden in the subform's properties tab.
Inherited component's event binding can be overriden in the subform's scripting editor. This can also be completely removed from the subform.
When a component is added to a superform, it will also appear in all forms that extend the superform.
When a component is deleted from a superform, it will also be removed from all forms that extend the superform.
All changes made to the base form UI will be propagated to child forms unless overridden.
A sub form will inherit all the methods of the super form. These methods can be overwritten. When this happens, Servoy will generate a method with a call to it's super in it. Inherited methods can be overriden in the subform's scripting editor. In order to override a method, you can right-click the method in the solex and select Override method
from the pop-up menu.
Example:
on base
form:
In the generated method there will be _super.onBeforeHide(event)
this will call the original method on the super form. This can be removed if the super code doesn't need to be called or code can be inserted before of after the call, if it is inserted after the super call don't forget to move the return
.
on new_employee
form:
Sample of code before:
Sample of code after:
Sample of removed super code:
The inherited form can be invoked in child forms (subforms).
Exemple:
on new_employee
form:
Methods that are defined to be private, will not be available for the subforms. By creation of a method there is a choice to make it private, public or protected. If a method is already created it can be done by adding '@protected', '@private' to the docs.
Public : public methods will be available because they are available everywhere
Private : private methods will not be available for any other forms, not even the subforms
Protected : protected methods will be available for the subform but not for other forms
An Abstract Form is a Form that does not implement any Form Parts and as such can not be shown to the user, but can contain business logic and can act as a Super Form for Child Forms.
Example:
base_code
form