Solved

Form inheritance and overriding functions.

Posted on 2001-08-10
8
283 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
[X]
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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 97
LAN or WAN ? 11 116
Unique identifier on a terminal server (rdp) 4 81
Dev express lookupcombo 3 62
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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