Autor Beitrag
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: So 05.11.06 13:42 
Kann man irgendwie ein array machen mit einem offenen ende??

lg el

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 05.11.06 13:46 
Meinst du ein dynamisches Array, bei dem die Anzahl der Einträge zur Entwurfszeit unbekannt ist?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
elundril Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: So 05.11.06 13:47 
jep genau das meine ich! einfach das ich so oft ich will das dazutun kann oder wegnehmen!

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: So 05.11.06 13:52 
Ein dynamisches Array ist so definiert:
ausblenden Delphi-Quelltext
1:
2:
var
  dynarray: array of TMeinTyp;

Die Anzahl der Einträge im Array kannst du so setzen:
ausblenden Delphi-Quelltext
1:
  SetLength(dynarray, Anzahl);					

Also immer wenn du das Array vergrößern bzw. verkleinern willst, rufst du SetLength auf.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: So 05.11.06 13:53 
Dazu musst du einfach die Schranken [A..B] in der Deklaration weglassen und dafür später mit Setlength(); die Länge deines Array festlegen ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
 MyDynArray: Array Of String;
Begin
 Setlength(MyDynArray, <Länge>);
 MyDynArray[2] := 'Blubb';
End;
elundril Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: So 05.11.06 13:57 
ok danke!

andere frage: wenn ich in einem dynamischen array einen wert mitendarunter weglösche, rutschen die nachfolgenden um eins weiter vor??


würde das funktionieren?
ausblenden Delphi-Quelltext
1:
setlength(dynamischen array, <länge vom dynamischen array+1>);					


wie lautet der befehl in den eckigen klammern??

lg el

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 05.11.06 13:57 
Die Anzahl der Einträge bekommst du mit Length(DeinArray) heraus.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: So 05.11.06 14:02 
user profile iconelundril hat folgendes geschrieben:
andere frage: wenn ich in einem dynamischen array einen wert mitendarunter weglösche, rutschen die nachfolgenden um eins weiter vor??

Nein. Das heißt, wie willst du einen mittendrin weglöschen? Das kannst du erst bei TList machen.
user profile iconMarco D. hat folgendes geschrieben:
Die Anzahl der Einträge bekommst du mit Length(DeinArray) heraus.

'Length' gibt glaub ich die Anzahl der Bytes zurück, 'High + 1' gibt die Anzahl der Einträge zurück, oder?
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: So 05.11.06 14:05 
user profile iconelundril hat folgendes geschrieben:
andere frage: wenn ich in einem dynamischen array einen wert mitendarunter weglösche, rutschen die nachfolgenden um eins weiter vor??

Nein, das Nachrutschen musst du selber machen.
MfG
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: So 05.11.06 14:07 
user profile iconChryzler hat folgendes geschrieben:

'Length' gibt glaub ich die Anzahl der Bytes zurück,

Nein, SizeOf gibt die Anzahl der Bytes zurück!
Größe <> Länge ;)


Zuletzt bearbeitet von Marc. am So 05.11.06 14:07, insgesamt 1-mal bearbeitet
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: So 05.11.06 14:07 
user profile iconChryzler hat folgendes geschrieben:
'Length' gibt glaub ich die Anzahl der Bytes zurück, 'High + 1' gibt die Anzahl der Einträge zurück, oder?

Nee quatsch. Length und High + 1 geben dasselbe zurück, nämlich die Anzahl der Einträge im dynamischen Array. SizeOf gibt die Anzahl der Bytes im dynamischen Array zurück.

EDIT: Zu spät :(


Zuletzt bearbeitet von Chryzler am So 05.11.06 14:09, insgesamt 1-mal bearbeitet
elundril Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: So 05.11.06 14:08 
mit ner for-schleife geht das am besten oder gibts was schnelleres/praktischeres?? und wie lass ich eines vorrücken??

lg el

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 05.11.06 14:08 
Du musst, wenn du was Löschen willst, alle Dinge, die dahinter liegen, um eins nach vorne rücken und dann das Array um 1 verkürzen.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: So 05.11.06 14:11 
user profile iconChryzler hat folgendes geschrieben:

'Length' gibt glaub ich die Anzahl der Bytes zurück, 'High + 1' gibt die Anzahl der Einträge zurück, oder?


nein, length gibt die Anzahl der Einträge aus. Hight gibt den höchsten "Index", das heißt DynArray[High(DynArray)] ist da letzte Element des Arrays


Wenn du einen Eintrag mittendrin löschen willst gibts die möglichkeit:

ausblenden Delphi-Quelltext
1:
2:
  DynArray[ToDelete]:=DynArray[high(Snowflake)];
  SetLength(DynArray,length(DynArray)-1);


so wird der letzte Eintrag dem Eintrag mit der Nummer ToDelete zugewiesen (der ist natürlich dann weg). Dann wird das array noch um 1 verkürzt, und der letzte Eintrag fällt weg, der ja jetzt an der Stelle ToDelete ist. Das funktioniert nur, wenn die Reihenfolge im Array egal ist.

//EDIT: Lol, hier kommen ja massig postings rein, bevor ich mitm schreiben fertig bin ;)

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: So 05.11.06 14:37 
Wenn du aus dem Array A mit dem Typ T den Wert mit dem Index B rauslöschen willst, und danach die Einträge nachrücken sollen, geht das so:
ausblenden Delphi-Quelltext
1:
2:
  Move(A[B + 1], Arr[B], (High(A) - B) * SizeOf(T));
  SetLength(A, High(A));