Recent

Author Topic: inherited  (Read 11160 times)

=sniper=

  • Guest
inherited
« on: June 18, 2006, 03:09:13 pm »
procedure TSomeClass.MyProc;
begin
  inherited;
...
end;
why I had this message "... Error: Abstract methods can't be called directly" but Delphi compile it without problem?

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
RE: inherited
« Reply #1 on: June 18, 2006, 03:30:21 pm »
if TSomeClass has a Parent which has
procedure MyProc; virtual; abstract;

then calling "inherited" equals calling an abstract method, which would crash.

If delphi compiles this it means it has less intelligent error handling than FPC.

Anonymous

  • Guest
RE: inherited
« Reply #2 on: June 18, 2006, 07:33:58 pm »
It look's like this
procedure MyProc(aTime : Integer); override;

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
RE: inherited
« Reply #3 on: June 19, 2006, 08:57:37 pm »
I need to see how the parent looks

Anonymous

  • Guest
RE: inherited
« Reply #4 on: June 19, 2006, 11:13:58 pm »
yes Parent class looks like
procedure MyProc(aElapsedTime : Integer); virtual; abstract;
now what should I do? Delete this inheriteds?

Anonymous

  • Guest
RE: inherited
« Reply #5 on: June 20, 2006, 07:32:36 am »
Parent class function actually

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
RE: inherited
« Reply #6 on: June 20, 2006, 07:58:47 am »
you can't call inherited in a descendent which has abstract method in parent.

Delphi perhaps let you run it but it'd crash on that code.

RudieD

  • Full Member
  • ***
  • Posts: 234
RE: inherited
« Reply #7 on: June 20, 2006, 08:22:15 pm »
No, I think Delphi just ignores it .
The FRED Trainer. (Training FRED with Lazarus/FPC)

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
RE: inherited
« Reply #8 on: June 21, 2006, 03:18:34 pm »
well it should throw an exception

RudieD

  • Full Member
  • ***
  • Posts: 234
RE: inherited
« Reply #9 on: June 21, 2006, 07:28:32 pm »
I also like the exception route.
The FRED Trainer. (Training FRED with Lazarus/FPC)

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2649
RE: inherited
« Reply #10 on: June 23, 2006, 10:49:07 am »
Yes and no.
In most cases you don't have to know what the original function does whan you want to add some functionality. IMO for those cases calling inherited should not raise an exception. (I find the FPC behaviour on this a bit annoying)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

RudieD

  • Full Member
  • ***
  • Posts: 234
RE: inherited
« Reply #11 on: June 23, 2006, 05:33:41 pm »
What about a warning message then ? So that if you expect a ancestors method to do something, you will at least know if theres nothing there.
The FRED Trainer. (Training FRED with Lazarus/FPC)

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
RE: inherited
« Reply #12 on: June 26, 2006, 05:54:44 pm »
no it should, abstract simply is ment to force programmers to make something. Otherwise use just an empty virtual one.

 

TinyPortal © 2005-2018