?
Solved

Virtual inheritence (I guess)

Posted on 2001-07-09
9
Medium Priority
?
188 Views
Last Modified: 2010-08-05
I have two form which must have the same public procedure, so I decide to create an abstract base class for them to inheritence like this.

TAbstractForm = class(TForm)
public
  function ShowX: integer; virtual; abstract;
end;

The two subclass forms look like this

TFormX = class(TAbstractForm)
public
  function ShowX: integer; virtual;
end;

function TFormX.ShowX: integer;
begin
  ShowModal;
  result := 217;
end;



I then want to call a procedure with either of the two forms like this

procedure TForm1.ShowMyForm( Form: TAbstractForm );
begin
  Form.ShowX;
end;

the actual call
..
begin
  ShowMyForm( FormX );
end;

I get this strange memory error when performing the last call. I guess because Delphi tries to execute ShowX of the abstract base class.
How do I handle this problem ?

BTW this was just a quick example I put together, so perhaps some details is forgotten or left out.
0
Comment
Question by:sorentop
[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
  • 4
  • 4
9 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6264467
I think this

TFormX = class(TAbstractForm)
public
 function ShowX: integer; virtual;
end;

must be

TFormX = class(TAbstractForm)
public
 function ShowX: integer; override;
end;
0
 
LVL 2

Expert Comment

by:ivobauer
ID: 6264476
Hi sorentop!

Just first look but,

instead

TFormX = class(TAbstractForm)
public
  function ShowX: integer; virtual;
end;

try

TFormX = class(TAbstractForm)
public
  function ShowX: integer; override;
end;

Hope this helps, Ivo
0
 
LVL 2

Expert Comment

by:ivobauer
ID: 6264491
Oh, damn! Only 2 minutes delay.

Ivo
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:sorentop
ID: 6264493
No I have tried it with override, but it didn't seem to help
0
 
LVL 2

Accepted Solution

by:
ivobauer earned 450 total points
ID: 6264512
sorentop:

> the actual call
>..
>begin
>  ShowMyForm( FormX );
>end;

Where does the FormX variable come from? Please post a code snippet where you get/create this var.

Ivo
0
 

Author Comment

by:sorentop
ID: 6264537
FormX is a form just like when you have Delphi create a default one. With the var in the interface section.

Instead of TForm1 = class(TForm) I have changed it to TFormX = class(TAbastractForm)

FormX is also created automatic by Delphi
0
 

Author Comment

by:sorentop
ID: 6264548
The creation look like this
Application.CreateForm(TFormX, FormX);
0
 

Author Comment

by:sorentop
ID: 6264580
Wait a minute. I have found the error, I turned out I assigned the variable of FormX in the Form1's OnCreation, before! FormX was created.
0
 
LVL 2

Expert Comment

by:ivobauer
ID: 6264623
OK. I have also tried to run the project and it worked well. But remember to always OVERRIDE the virtual (abstract) method otherwise when you declare the method with same name with virtual directive in descendant class, you simply declare another method (and hide ancestor's one) and in case the original method was abstract, you get EAbstractError exception when attempting to call an abstract method.

Best regards, Ivo.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

801 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