Autor Beitrag
Delphi2009lover
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 176



BeitragVerfasst: So 13.12.09 20:20 
Hey,

ich habe ein Array

A[0] := 'A';
A[1] := 'B';
...
A[25] := 'Z';


Wie kann ich jetzt den Buchstaben "B" rauslöschen? (Länge des Arrays soll am Schluss natürlich 25 und nich wie vorher 26 sein)
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 13.12.09 20:21 
Da musst du in einer Schleife das Array durchgehen, und alle Einträge ab dem 'A' um eins nach vorne schieben. Anschließen Setlength aufrufen und da die Länge des Array passend setzen.

_________________
We are, we were and will not be.
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: So 13.12.09 20:32 
Wenns um performance geht, könnte man das array auch als Pointer verwalten, dann den Platz vom 'A' freigeben, und in Das 'B' ein 'A' schreiben.
Oder Gleich eine pointerliste (Delphi-Objekt TList) nehmen.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 13.12.09 20:34 
Wobei die TList auch nur ein Array ist. Sieht zwar wie eine Liste aus und stellt die Operationen Insert etc. bereit, aber intern wird da wild umherkopiert. TList ist keine verkettete Liste!

_________________
We are, we were and will not be.
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: So 13.12.09 20:35 
Aber bei TList braucht man nur die Pointer verschieben, und nicht die Werte.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 13.12.09 20:38 
Und genau das stimmt nicht. Wenn du in einer TList das erste Element löschst, dann wird das gelöscht, und der ganze Krempel dahinter wird eine Position nach vorne kopiert. Ob dabei die Chars kopiert werden, oder die Pointer darauf, spielt eigentlich keine Rolle.

_________________
We are, we were and will not be.
Nano-Ware
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 7



BeitragVerfasst: So 13.12.09 20:47 
Das mit dem Nachvornesetzen habe ich schon versucht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
for I := FR_MAIN.LIST_VIDEO.Selected.Index to Length(ListArray) - 1 do
  begin

    ListArray[I][0] := ListArray[I + 1][0];
    ListArray[I][1] := ListArray[I + 1][1];
    ListArray[I][2] := ListArray[I + 1][2];
    ListArray[I][3] := ListArray[I + 1][3];
    ListArray[I][4] := ListArray[I + 1][4];
    ListArray[I][5] := ListArray[I + 1][5];
    ListArray[I][6] := ListArray[I + 1][6];

  end;


FR_MAIN.LIST_VIDEO ist eine TListView


Meldung zu wenig Arbeitsspeicher...


Thx schon mal jetzt
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: So 13.12.09 22:25 
Du kommst über die Array-Grenzen!
Wenn dann, muss die Schleife bis Length(ListArray) - 2 gehen, da du immer ein i+1 hast