Autor Beitrag
beljo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 129



BeitragVerfasst: Mi 12.04.06 13:25 
Hallo,
ich möchte einzelne Elemente aus einem Array entfernen und an dieser Stelle alle anderen Arrayelemente "nachrücken",
ausblenden Delphi-Quelltext
1:
2:
for i:=0 to length(c)-1  do
 if length(c[i])<2 then  c[i].delete;   // oder so ähnlich???

Mir fehlt nur der Befehl zum Löschen eines Elementes aus dem Array, sofern der rest des Treats richtig ist.
Das Nachrücken der Elemente dürfte kein Problem sein ( denke ich ;-))
cu


Moderiert von user profile iconraziel: Topic aus Dateizugriff verschoben am Do 13.04.2006 um 13:02
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 12.04.06 13:27 
Bei einem dynamischen Array setzt du, nachdem du die Inhalte nachgerückt hast, einfach die Länge neu (SetLengh).
beljo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 129



BeitragVerfasst: Mi 12.04.06 13:49 
Ich hab mir die Hilfe etwas angeschaut um etwas über Setlegh zu finden.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
for i:=0 to length(c)-1  do
 if length(c[i])<2 then
  begin
    c[i]:= c[i+1];
    max:= max-1;
    SetLengh(c,max);
  end;

Leider klappt das so nicht wird die Länge das Arrays c nicht so verkürzt?
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Mi 12.04.06 14:01 
Ein dynamisches array bekommt mit SetLength eine neue Länge zugewiesen.

SetLength(MyArray,1) bewirkt dass MyArray nur noch 1 Element groß ist
SetLength(MyArray,20) .... 20 Elemente

Um ein Element aus einem dynamischen Array zu löschen muss aber etwas mehr aufwand betrieben werden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
 procedure DeletePositionFromArray(var inputarray : TMyArray; position : integer);
  var i : integer;
  begin
    if position < high(inputarray) then
      for i:=position to high(inputarray)-1 do
        inputarray[i]:=inputarray[i+1];

    SetLength(inputarray, high(inputarray));
  end;


Diese Prozedure nimmt ein vorher definiertes TMyArray als Variable und löscht das Element mit dem index "position" raus.
TMyArray könnte zu Beispiel sein

ausblenden Delphi-Quelltext
1:
2:
type
  TMyArray : array of string;



hier das ganz ohne TMyArray:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
if position < high(inputarray) then
   for i:=position to high(inputarray)-1 do
      inputarray[i]:=inputarray[i+1];

  SetLength(inputarray, high(inputarray));

_________________
Delphi: XE - OS: Windows 7 Professional x64
beljo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 129



BeitragVerfasst: Do 13.04.06 10:46 
Vielen Dank Horschdware,
verstehe nicht warum objektPascal an einigen Stellen echt umständlich ist.
Naja was solls da kann man nicht machen.
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Do 13.04.06 12:05 
Hallo,

Hab mal ein paar Off-Topic Beiträge bezüglich der Forenwahl von beljo abgetrennt. Meldet doch das Topic einfach über den user defined image Thema melden-Link, anstatt das Topic mit OffTopic zuzukleistern.

Danke,
raziel

_________________
JSXGraph