Autor Beitrag
nepleurepas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164

Win XP

BeitragVerfasst: Fr 08.05.09 19:23 
Hallo,
wie kann ich den ein dynamisches array kopieren?

Denn wenn ich zum beispiel mache
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var a,b: array of integer;
begin
setlength(a,5);
setlength(b,5);
a[4]:= 99;
b:= a;
b[4]:= 77;
end;


dann wird ja a[4] auch zu 77, da man eben nur den zeiger kopiert hat. Aber wie kann ich jetzt eine wirkliche kopie von a anfertigen, die ich verändern kann, ohne dass ich auch a verändert? Ich werde ja wohl nicht mit einer schleife jeden wert einzeln kopieren müssen, oder?

dankeschön für antworten
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 08.05.09 19:24 
Moin!

Schau dir mal Copy() an, die Funktion kann auch (dyn.) Arrays kopieren. :idea: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Fr 08.05.09 19:28 
Also die einfachste Lösung wäre ja so:
ausblenden Delphi-Quelltext
1:
2:
for i:=0 to length(a) do
     a[i]:=b[i];

Ich weiß nur leider nicht, ob man so anfangen sollte...
Ich mache es jetzt (leider) immer so.
nepleurepas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164

Win XP

BeitragVerfasst: Fr 08.05.09 19:33 
jau danke euch beiden. "copy" hab ich gesucht.
Die schleifenlösung war mir ja schon bekannt...