Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Prototyp einer Klasse erstellen (https://www.delphipraxis.net/145985-prototyp-einer-klasse-erstellen.html)

MisterNiceGuy 11. Jan 2010 23:05


Prototyp einer Klasse erstellen
 
Hi, ist es möglich in Delphi einen Prototyp einer Klasse zu erstellen. Grund ist ich will folgendes realisieren:

Delphi-Quellcode:
type TClass1 = class(TObject)
   public
      a:TClass2;
end;

type TClass2 = class(TObject)
   public
      b:TClass1;
end;
Natürlich ist TClass2 in TClass1 nicht bekannt und umgekehrt. Daher meine Frage:
Ist es möglich, dass ich vor die Definition von TClass1 noch einen Klassenprototyp von TClass2 schreibe?
z.B. so:
Delphi-Quellcode:
type TClass1;
Danke für eure Hilfe :)

s.h.a.r.k 11. Jan 2010 23:07

Re: Prototyp einer Klasse erstellen
 
Steht hier im Forum glaube mehrere hunderte Male :zwinker:

Delphi-Quellcode:
// Korrigierte Fassung...
type

TClass2 = class; // Fehler: Hier war das "(TObject)" zu viel

TClass1 = class(TObject)
public
  a:TClass2;
end;

TClass2 = class(TObject)
public
  b:TClass1;
end;
Edit: Hier noch ein interessanter Link für dich: http://www.delphipraxis.net/internal...t.php?t=171094

Korrektur des Quelltextes, sodass es hier nun auch richtig steht.

MisterNiceGuy 11. Jan 2010 23:17

Re: Prototyp einer Klasse erstellen
 
Da bekomm ich beim dritten Typ einen "Identifier redeclared"... Ist das in Delphi7 schon möglich?

Sir Rufo 11. Jan 2010 23:21

Re: Prototyp einer Klasse erstellen
 
Zitat:

Zitat von MisterNiceGuy
Da bekomm ich beim dritten Typ einen "Identifier redeclared"... Ist das in Delphi7 schon möglich?

So ist es richtig
Delphi-Quellcode:
type
  TFoo1 = class;
  TFoo2 = class
    Foo1 := TFoo1;
  end;
  TFoo1 = class
    Foo2 : TFoo2;
  end;
So ist es falsch, bzw. gibt einen Fehler
Delphi-Quellcode:
type
  TFoo1 = class;
type
  TFoo2 = class
    Foo1 := TFoo1;
  end;
type
  TFoo1 = class
    Foo2 : TFoo2;
  end;
So hat s.h.a.r.k das ja auch geschrieben, aber nicht explizit drauf hingewiesen ;)

s.h.a.r.k 11. Jan 2010 23:23

Re: Prototyp einer Klasse erstellen
 
Ich hatte das (TObject) zu viel. Das hat man davon, dass der Firefox nicht automatisch den Quelltext, den man hier schreibt, compiliert :mrgreen:

Sir Rufo 11. Jan 2010 23:24

Re: Prototyp einer Klasse erstellen
 
Zitat:

Zitat von s.h.a.r.k
Ich hatte das (TObject) zu viel. Das hat man davon, dass der Firefox nicht automatisch den Quelltext, den man hier schreibt, compiliert :mrgreen:

uppss, das hatte ich auch übersehen :mrgreen:


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:35 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz