Link to home
Start Free TrialLog in
Avatar of Richard Quadling
Richard QuadlingFlag for United Kingdom of Great Britain and Northern Ireland

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.ValidateForm : 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.
Avatar of kretzschmar
kretzschmar
Flag of Germany image

you could it define as a dummy as any other mehod like

function TTemplateForm.ValidateForm : Boolean;
begin

end;

or with the virtuel-directive
in your templateform type declaration

(just from head, misunderstanding possible)

meikl ;-)
ASKER CERTIFIED SOLUTION
Avatar of Jason Sweby
Jason Sweby
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
hi igor :-)
Hi meikl,
just reread your comment and found the same idea :-)

Avatar of Richard Quadling

ASKER

Thanks for the ideas.

I've got it working with a procedure and a variable parameter.

Regards,

Richard Quadling.