1- Si la matriz no contiene ninguna cadena o una tabla dinámica, puede utilizar movimiento, pero matrices dinámicas no deben ser manejados como matrices de tamaño fijo:
var A,B: array[0..10] of integer;
DA, DB: array of double;
i: integer;
begin
for i := low(A) to high(A) do
A[i] := i;
move(A[0],B[0],length(A)*sizeof(A[0])); // first version, compiler does the stuff
move(A[0],B[0],sizeof(A)); // it works
move(A[0],B[0],40); // if you know what you're doing, since sizeof(A)=40
SetLength(DA,10); // DA[0]..DA[9]
for i := 0 to high(DA) do // or for i := 0 to 9 if you know what you're doing
DA[i] :=
SetLength(DB,length(DA));
if length(DA)<=length(DB) then // if your dynamic array may be void, use this before to avoid GPF
move(DA[0],DB[0],length(DA)*sizeof(DA[0]));
if pointer(DA)<>nil then // this will just check that DA[] is not void
move(pointer(DA)^,pointer(DB)^,length(DA)*sizeof(double)); // similar to previous
end;
2- Si la matriz contiene cadenas o otra matriz contenido de referencia, hay que utilizar un bucle:
var A,B: array[0..10] of string;
i: integer;
begin
for i := 0 to high(A) do
A[i] := IntToStr(i);
for i := 0 to high(A) do
B[i] := A[i]; // this doesn't copy the string content, just add a reference count to every A[], and copy a pointer: it's very fast indeed
end;
Move usa un bucle for. Al menos lo hizo en Delphi 7. ¿Qué código causó el error? –
No lo sabía. Mover y Copiar ambos causaron un error. (No los usé al mismo tiempo) – Dian
Move no usa un ciclo for. Está escrito en asm, incluso en Delphi 7, y usa un rep movsd/movsb con Delphi 7, o instrucciones FPU mucho más rápidas en la versión más nueva de Delphi. –