Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

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.
0
Richard Quadling
Asked:
Richard Quadling
  • 3
  • 2
  • 2
  • +1
1 Solution
 
kretzschmarCommented:
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 ;-)
0
 
jswebyCommented:
From where I'm sitting, instead of having a function that returns True/False, you should have a procedure with a variable parameter that takes the true/false result; then you can use the inheritance.

J.

0
 
kretzschmarCommented:
good point, j :-)
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
jswebyCommented:
Thanks, k. Inheritance isn't my strong point, though...
0
 
ITugayCommented:
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.
0
 
kretzschmarCommented:
hi igor :-)
0
 
ITugayCommented:
Hi meikl,
just reread your comment and found the same idea :-)

0
 
Richard QuadlingSenior Software DeveloperAuthor Commented:
Thanks for the ideas.

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

Regards,

Richard Quadling.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now