Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Form inheritance and overriding functions.

Posted on 2001-08-10
8
281 Views
Last Modified: 2010-04-06
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
Comment
Question by:Richard Quadling
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6372068
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
 
LVL 4

Accepted Solution

by:
jsweby earned 150 total points
ID: 6372093
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6372125
good point, j :-)
0
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.

 
LVL 4

Expert Comment

by:jsweby
ID: 6372133
Thanks, k. Inheritance isn't my strong point, though...
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6372137
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6372152
hi igor :-)
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6372167
Hi meikl,
just reread your comment and found the same idea :-)

0
 
LVL 40

Author Comment

by:Richard Quadling
ID: 6372189
Thanks for the ideas.

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

Regards,

Richard Quadling.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question