Autor Beitrag
fuggaz
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 106



BeitragVerfasst: Di 29.01.08 14:59 
Hey,

Kann ich einen dynamischen n-dimensionalen array programieren?

Bsp.:
var meinarray:array[1..x]
als nächstes dann während das programm läuft (mittels setlength? ) dazu veränder:
meinarray:array[1..x,1..x]
und dann
meinarray:array[1..x,1..x,1..x]
usw.

Gibt es da eine Möglichkeit?


Zuletzt bearbeitet von fuggaz am Mo 04.02.08 20:06, insgesamt 1-mal bearbeitet
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Di 29.01.08 15:01 
Wenn du 1..x angibst, ist es ja nicht mehr dynamisch ;)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var MeinArray: array of array of integer;
begin
  SetLength(MeinArray, 2, 5);
  MeinArray[1,3] := 1000;
end;


So sollte es das theoretisch tun?
fuggaz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 106



BeitragVerfasst: Mo 04.02.08 16:12 
Dann hätte ich aber nur eine array of array.
Was ich aber brauche ist ein array of array of array of ar..............
Wenn das nicht geht, dann naja auch egal.
Konnte sowas schon öfters mal gebrauchen.
Gibt meistens eine andere Lösung aber praktisch wäre das schon.
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Mo 04.02.08 16:17 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
type
  TArray2D = array of array of Integer;
  TArray3D = array of array of array of Integer;
  TArray4D = array of array of array of array of Integer;
var
  A2: TArray2D;
  A3: TArray3D;
  A4: TArray4D;
begin
  SetLength(A2,4,8);
  SetLength(A3,5,7,9);
  SetLength(A4,1,3,6,8,);
end;

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Mo 04.02.08 16:48 
Hi,

Ich glaube gemeint ist ein Array, dessen Dimensionenzahl dynamisch änderbar ist!

mfG,
Daniel

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
fuggaz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 106



BeitragVerfasst: Mo 04.02.08 17:27 
Ja genau das mein ich einen array, dessen Dimensionenzahl man ändern kann.
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Mo 04.02.08 17:42 
fertige Kontrukte gibt es dafür in Delphi nicht, dass wirst Du selbst implementieren müssen!

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Mo 04.02.08 17:53 
Hi,

Also mir fällt nur 'ne ganz unpraktische Lösung ein:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
type
  TDimension = class(Tobject)
  end;
  TNewDimension = class (TDimension)
    FValue: TDimension;
  end;
  TFinalDimension = class (TDimension)
    FValue: Integer;  //z.B.
  end;

Funktionen, die du brauchst(z.B. length()) musst du noch nachprogrammieren.

Ich glaub ich steh aufm Schlauch, das muss doch auch mit records gehen...
Listen müssten doch gehen, also mit jedes Element kennt seinen Nachfolger...

hab noch nicht mit Listen gearbeitet, aber so:?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
TKettenelement = record
  kenntNächste: TKettenelement;  //oder 'n Zeiger drauf? Das muss sich nochmal wer anders anschauen
  istLetzte: Boolean;
  Value: array of TKettenelement;


Änder mal den Threadtitel, das wird nicht so ganz dutlich.
Array mit dynamischer Dimensionenzahl wäre z.B. besser.

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
fuggaz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 106



BeitragVerfasst: Sa 09.02.08 18:40 
ok danke für die Antworten.

Das es keine integrierte Funktion dafür gibt beantwortet meine Frage.
Wie gesagt gibt es meist einen anderen Weg wie man es machen kann.


mfg fuggaz
nagel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: Sa 09.02.08 18:43 
Kann mir grad nix vorstellen wo man das brauchen würde.
Kannst du mir ein Beispiel geben?
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Sa 09.02.08 19:01 
fuggaz, zeig doch mal bitte Code, der auf ein Array mit dynamischer Anzahl von Dimensionen zugreifen soll... :wink:

_________________
Na denn, dann. Bis dann, denn.
fuggaz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 106



BeitragVerfasst: Sa 09.02.08 19:33 
@alzaimar:alles Überlegungen, keine Codes, weil es eben nicht geht;)
@nagel:ein Problem eines Freundes hatte mit einem n-d-sodoku zu tun. Alles soll variabel sein.
Also Spaltenanzahl, Dimensionsanzahl.
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Sa 09.02.08 21:05 
Du kannst ein variantes Array zur Laufzeit mit beliebig vielen Dimensionen füllen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Function CreateArray (aDimensions : integer) : Variant;
Var
  bounds : Array Of Integer;
  i : Integer;

Begin
  setLength (bounds, 2*aDimensions);
  For i:=0 to aDimensions-1 do begin
    bounds[2*i] := 0;
    bounds[2*i+1] := 10;
    End;
  Result := VarArrayCreate(bounds, varDouble);
End;

Die Demo erzeugt jeweils 11 Elemente pro Dimension.

Wie man aber darauf zugreift, bleibt Dir überlassen (geht natürlich auch).

_________________
Na denn, dann. Bis dann, denn.
fuggaz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 106



BeitragVerfasst: So 10.02.08 15:58 
Au backe^^
Danke erstmal dafür.
So direkt versteh ich es noch nicht.
Ich werde es aber mal auseinandernehmen.