Autor Beitrag
Basti
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 345

Windows Vista
D2005 Pers, D7 Pers
BeitragVerfasst: So 02.01.05 18:59 
Hallo Leute, ich habe gerade ein echtes Problem.
Ich versuche es mal zu formulieren und danach gibt's den Quelltext.

Ich habe eine Klasse X.
Diese Klasse X besitzt eine private Funktion F, die als Parameter einen Array von X benötigt.
Da ich als Parameter bekanntlich nicht ": Array of X" angeben darf, muss ich vorher einen Typ deklarieren.
Aber ich kann diesen Typ nicht vorher deklarieren, weil die Klasse zuvor noch nicht bekannt ist.
Nach der Klasse kann ich ihn auch nicht deklarieren, weil dann die Funktion in der Klasse den Typen
wieder nicht kennt.

Wie mache ich das nun?
Um das Wirrwar etwas einfacher zu machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
type
  class X
  private
    function F(a: Array of X):Boolean;  // Fehler: falsche Parameterübergabe
  public
  end;



ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
type
  XArray = Array of X;   // Fehler: X unbekannt
  class X
  private
    function F(a: XArary):Boolean;
  public
  end;



ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
type
  class X
  private
    function F(a: XArary):Boolean;  // Fehler: XArray unbekannt
  public
  end;
  XArray = Array of X;


Ich hoffe ihr könnt mir helfen.
Ich sehe momentan auch keine andere Möglichkeit als diesen Array.

PS @Grayfox: Ich freue mich auf das große S. :lol:

_________________
Der Computer ist die logische Weiterentwicklung des Menschen: Intelligenz ohne Moral.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: So 02.01.05 19:07 
wie wäre es wenn du 2 unterschiedliche Klassen hernimmst ?
z.b.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Type
    a = Class;
    b = class(a)
      function F(abc:array of a):boolean;
    end;
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 02.01.05 19:07 
Funzt das (ungetestet, da kein Delphi bei der Hand)?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
type
  X; forward;
  XArray; forward;

type  
  class X  
  private  
    function F(a: XArary):Boolean;  // Fehler: XArray unbekannt  
  public  
  end;  
  XArray = Array of X;


Unschön aber müsste eigentlich gehen

AXMD
Basti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 345

Windows Vista
D2005 Pers, D7 Pers
BeitragVerfasst: So 02.01.05 19:19 
Leider nicht:
Delphi Compiler hat folgendes geschrieben:
[Fehler] '=' erwartet, aber ';' gefunden

Kann mir auch gar nicht vorstellen was das macht - mal schnell in der Delphi Hilfe schauen.

_________________
Der Computer ist die logische Weiterentwicklung des Menschen: Intelligenz ohne Moral.
mad_progger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 49

WIN XP, Linux
D7 Pro
BeitragVerfasst: So 02.01.05 19:32 
auf den ersten Blick gesagt:
erst deklariert ihr einen Typ XArray und beim Aufruf sagt ihr: XArary
Da liegt der Hund begraben!

Also:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
  xarray = array of x;
  x = class
  private
    function F(a: XArray):Boolean;
  public
  end;


Werter AXMD,
euer type "class X" ist falsch. Das müsste "type x=class" lauten. Eventuell noch die Klasse, von der abgeleitet wird!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 02.01.05 19:45 
Hallo!

So geht das mit dem forwarden:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
type
  X = class;

  XArray = Array of X;

  X = class(TObject)
  private
    function F(a: XArray): Boolean;
  public
  end;


MfG
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Basti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 345

Windows Vista
D2005 Pers, D7 Pers
BeitragVerfasst: So 02.01.05 20:29 
Ja, so geht es.
Aber dummerweise kommt dann ein neuer Fehler.

Wegen dem hier drunter folgenden Post habe ich den Text hier geändert.
Danke für eure Hilfe, das neue Problem findet ihr unter
www.delphi-forum.de/....php?p=203397#203397 :)
Also Danke für eure Hilfe.

_________________
Der Computer ist die logische Weiterentwicklung des Menschen: Intelligenz ohne Moral.


Zuletzt bearbeitet von Basti am So 02.01.05 20:57, insgesamt 1-mal bearbeitet
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 02.01.05 20:43 
Hallo!

Das ist ein neues Problem. Mache dafür bitte einen neuen Thread auf.

Danke :-)
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".