Autor Beitrag
YiB
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 22

Win XP Pro, Knoppix

BeitragVerfasst: Fr 23.09.05 19:11 
Hi ihr alle! Ich schreib grad mein erstes brauchbares Programm in Delphi, und frag mich jetzt ob es eine Funktion gibt,
um irgendein Element aus einem dynamischen Array zu löschen, oder ob ich das mit einer Schleife tun muss. In der Hilfe
find ich grad nichts darüber
MfG, YiB
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 23.09.05 19:31 
Welche Datentypen hast Du in deinem Array? Ordinal, Strings, Records, Arrays?

Je nach dem entscheided es sich, welche Möglichkeiten am besten funktioniert.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
YiB Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 22

Win XP Pro, Knoppix

BeitragVerfasst: Fr 23.09.05 21:11 
Ich hab Records...
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 23.09.05 23:09 
Sofern deine Records keine Strings oder weitere dyn. Arrays beinhalten, kannst Du mit dem Move-Befehl gefolgt von einem SetLength(Arr, High(Arr)); relativ schnell das Element in der Mitte entfernen.

Das erfordert aber jedesmal einen relativ hohen Aufwand beim Kopieren, wodurch die Performance stark beeinträchtig werden kann.

Die Parameter für Move lauten folgendermaßen:
ausblenden Delphi-Quelltext
1:
2:
3:
Dest := Arr[IndexToDelete];
Src  := Arr[IndexToDelete + 1];
Size := SizeOf(TDeinRecord) * (High(Arr) - IndexToDelete);

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Grishnak
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Sa 24.09.05 00:02 
Wenn die Records nicht sortiert sind (bzw. die Reihenfolge keine Rolle spielt), geht auch:

ausblenden Delphi-Quelltext
1:
2:
if IndexToDelete < High(Arr) then Arr[IndexToDelete]:=Arr[High(Arr)];
SetLength(Arr, Length(Arr)-1);

Wie das allerdings Performance-Technisch aussieht, weiß ich nicht..!

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!
YiB Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 22

Win XP Pro, Knoppix

BeitragVerfasst: Sa 24.09.05 12:08 
Also erstmal danke für eure Hilfe!
Die Performance macht in diesem Fall fast garnichts aus, da das Array höchstens so ca 50 Elemente haben wird und auch nur sehr selten was daraus gelöscht wird.

@Grishnak: die Methode wird wohl am besten funktionieren, danke!