Einzelnen Beitrag anzeigen

compix

Registriert seit: 13. Feb 2011
14 Beiträge
 
#8

AW: Werte von Variablen der Hauptklasse innerhalb einer abgeleiteten Klasse verwenden

  Alt 6. Jul 2011, 14:11
So, tut mir leid, dass ich mich erst jetzt wieder melde, ihr habt natürlich recht, ich hätte das ganze noch genauer gestalten müssen, also:
unit 1:

procedure TForm1.Button1Click(Sender: TObject);
Var HauptKlasse:THauptKlasse;
begin
HauptKlasse:=THauptKlasse.Create;
HauptKlasse.xInKindKlasse;
end;

unit 2:
interface
type THauptKlasse=class(TObject)
protected
x:integer;
public
procedure xInKindKlasse;
end;

implementation
uses unit3;



procedure THauptKlasse.xInKindKlasse;
var KindKlasse:TKindklasse;
begin
x:=10; //<---x wird hier auf 10 gesetzt
KindKlasse:=TKindKlasse.create;
KindKlasse.xInhalt;
end;

end.

unit 3:
interface
uses unit2,dialogs,sysutils;
type TKindKlasse=class(THauptKlasse)
public
procedure xInhalt;
end;
implementation

procedure TKindKlasse.xInhalt;
begin
Showmessage(inttostr(x)); // der Inhalt ist 0, also x=0... Wieso?
end;

end.
  Mit Zitat antworten Zitat