Autor Beitrag
Bayo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Do 25.07.02 12:14 
Hi zusammen

Ich habe da ein kleines Problem mit Methodenüberlagerung :-(: Sobald ich in einer Funkton die Verarbeitung ihrer Superklasse aufrufe bzw. Inherited, bringt der Compiler die Fehlerbildung: Incompatible types

Ändere ich die Funktion in einer Prozedur und lasse somit den Rückgabewert weg, funktioniert es! Kann ich in einer Funktion kein Inherited aufrufen? Wenn ja, wieso nicht? Natürlich kann ich dieses Problem mit einem Var-Parameter und einer Prozedur lösen, es interessiert mich aber, ob das wirklich nicht geht!

Hier ein gekürztes Beispiel:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
TKlasse1 = class(TObject)
  function test: Boolean; Virtual;
end;

TKlasse2 = class(TKlasse1)
  function test: Boolean; Override;
end;

implementation

function TKlasse1.test: Boolean;
begin
  Result := False;
  Mach etwas;
  Result := True;
end;

function TKlasse2.text: Boolean;
begin
  Result := False;
  Mach etwas anderes;
  Result := True;
  Inherited;
end;


Ich bedanke mich für jede Antwort!!

Grüsse Dominic
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Do 25.07.02 12:21 
Das müsste so gehen:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
function TKlasse2.text: Boolean; 
begin 
  Result := False; 
  Mach etwas anderes; 

  Result := Inherited; 
end;
Denn Inherited liefert ja auch ein Ergebnis zurück!

Gruß
Bayo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Do 25.07.02 13:01 
Ja, das würde sinn machen... hab ich auch schon probiert, funktioniert leider auch nicht!

Trotzdem danke ich für deine Antwort :-) Grüsse Dominic
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Do 25.07.02 13:17 
Sorry, muss natürlich so sein:
ausblenden Quelltext
1:
Result := Inherited Test;					

Gruß
TINO
wwerner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 185



BeitragVerfasst: Do 25.07.02 13:18 
TKlasse1 = class(TObject)
function test: Boolean; Virtual;
end;

TKlasse2 = class(TKlasse1)
function test: Boolean; Override;
end;

implementation

function TKlasse1.test: Boolean;
begin
Result := False;
Mach etwas;
Result := True;
end;

function TKlasse2.test: Boolean;
begin
Result := False;
Mach etwas anderes;
Result := True;
Inherited test;
end;

_________________
Gruß

Wolfgang

----------
zu hause ist es doch am schönsten
Bayo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Do 25.07.02 14:05 
Yep, das haupt hin :-) Ich bedanke mich für die Antworten!!

Grüsse Dominic