Richard Quadling
asked on
Form inheritance and overriding functions.
I have a form which is used as a template (via inheritance) to create "real" forms (via New ... and choosing my template form).
(Don't know the right terminology, so please excuse me!).
The form contains a whole load of controls with some basic events behind them.
One of the events needs to call a validation routine.
This routine is different for each of the real forms.
So.
frmMaint is the template form.
frmMaintUsers is one of the new forms, based on frmMaint, frmMaintJobs is another.
The frmMaint form has an event on the OK button to determine if the values can be saved.
I would like to be able to have in the OK event something like ...
if (ValidateForm) then ...
Where ValidateForm can be different for each of the new forms as the actual things to be validated are different.
In the new forms, I am expecting something like ...
function TfrmMaintUsers.ValidateFor m : Boolean;
begin
inherited;
// Do my validation now.
Result := whatever;
end;
I do not know how to declare this function in the template form nor in the new form so that it is inherited properly.
Ideas/suggestions/examples please.
Regards,
Richard Quadling.
(Don't know the right terminology, so please excuse me!).
The form contains a whole load of controls with some basic events behind them.
One of the events needs to call a validation routine.
This routine is different for each of the real forms.
So.
frmMaint is the template form.
frmMaintUsers is one of the new forms, based on frmMaint, frmMaintJobs is another.
The frmMaint form has an event on the OK button to determine if the values can be saved.
I would like to be able to have in the OK event something like ...
if (ValidateForm) then ...
Where ValidateForm can be different for each of the new forms as the actual things to be validated are different.
In the new forms, I am expecting something like ...
function TfrmMaintUsers.ValidateFor
begin
inherited;
// Do my validation now.
Result := whatever;
end;
I do not know how to declare this function in the template form nor in the new form so that it is inherited properly.
Ideas/suggestions/examples
Regards,
Richard Quadling.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
good point, j :-)
Thanks, k. Inheritance isn't my strong point, though...
Hi RQuadling,
you can declare virtual method in frmMain form:
TFrmMainForm = class(..)
public
function IsFormValid: Boolean; virtual; // abstract
and then write your own implementation on inherited forms.
-----
Igor.
you can declare virtual method in frmMain form:
TFrmMainForm = class(..)
public
function IsFormValid: Boolean; virtual; // abstract
and then write your own implementation on inherited forms.
-----
Igor.
hi igor :-)
Hi meikl,
just reread your comment and found the same idea :-)
just reread your comment and found the same idea :-)
ASKER
Thanks for the ideas.
I've got it working with a procedure and a variable parameter.
Regards,
Richard Quadling.
I've got it working with a procedure and a variable parameter.
Regards,
Richard Quadling.
function TTemplateForm.ValidateForm
begin
end;
or with the virtuel-directive
in your templateform type declaration
(just from head, misunderstanding possible)
meikl ;-)