Autor Beitrag
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 20.10.10 23:08 
Hallo.

Ich habe eine Eltern-Klasse mit einer abstrakten Methode. Die davon abgeleiteten Klassen implementieren nun diese Methode, ganz wie es sein soll.
Nun kam es aber vor, dass ich (blöd wie ich bin) bei einer Klasse vergessen habe, eine abstrakte Methode auszuführen.
Der Compiler hat nicht gemeckert und das kommt mir komisch vor.
Ich weiß jetzt nicht, ob ich das mit anderen Programmiersprachen durcheinander bringe, aber ich dachte immer, abstrakte Methoden müssen in den abgeleiteten Klassen immer zwingend implementiert werden? Oder bin ich da auf dem Holzweg.

Matze

_________________
In the beginning was the word.
And the word was content-type: text/plain.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mi 20.10.10 23:10 
Delphi gibt nur eine Warnung aus. Zur Laufzeit gibt's beim Aufruf eine EAbstractError.
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 20.10.10 23:12 
Knallt zur Laufzeit...
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 20.10.10 23:33 
Also ich bekomme eine Meldung.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
type
  TAbs = class
    procedure Test; virtual;abstract;
  end;

  TDes = class(TAbs)
  end;

procedure TForm1.Button1Click(Sender: TObject);
var a: TDes;
begin
  a:= TDes.Create;
  try
    //dummy
  finally
    a.free;
  end;
end;

ausblenden Quelltext
1:
[Warnung] Unit1.pas(39): Instanz von 'TDes' mit der abstrakten Methode 'TAbs.Test' wird angelegt					

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Do 21.10.10 10:48 
user profile iconbummi hat folgendes geschrieben Zum zitierten Posting springen:
Knallt zur Laufzeit...

Ja ganz genau. Das ist ja das Blöde.

Und ja: Stimmt, man bekommt ne Meldung, allerdings nur ne Warnung. Ich dachte, dass das dann einfach nicht kompilliert...
Und die Warnung ist blöderweise auch nicht immer zu sehen.

Danke trotzdem an alle!

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Lemmy
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 792
Erhaltene Danke: 49

Windows 7 / 10; CentOS 7; LinuxMint
Delphi 7-XE10.1, VS 2015
BeitragVerfasst: Do 21.10.10 10:57 
Hi,

hier stellt Delphi dem Entwickler wohl zu, selbst seinen Code ausreichend zu kennen. Ich glaube in C# wäre so was nicht möglich zu kompilieren.

Hier habe ich mir inzwischen angewöhnt, wenn ich eine Klasse ableite bei der Definition STRG+Leertaste zu drücken. In der Liste werden abstrakte Methode alle in roter Schrift aufgeführt, und die haue ich dann alle gleich in die Klasse rein....
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Do 21.10.10 11:03 
Ahhh. Guter Tipp.
Danke!

_________________
In the beginning was the word.
And the word was content-type: text/plain.