[fpc-pascal] Copy dynamic array

Alexander Grotewohl alex at dcclost.com
Wed May 16 00:49:30 CEST 2018


type
   TRec = record
     s1:string;
     i1:integer;
   end;

var
   S1,S2:string;
   R1,R2:TRec;
begin
   S1:='123';
   S2:=S1; // lol

   R1.s1:='123';
   R1.i1:=1;
   move(R1, R2, sizeof(TRec));
   writeln(R2.s1, ' ', R2.i1);
end.


On 5/15/2018 2:39 PM, denisgolovan wrote:
> Well.
>
> "Copy" works for arrays only.
> Neither strings nor records work.
> Tested in pretty old svn rev. 37656
>
> //=================================================
> program project1;
>
> {$mode objfpc}{$H+}
>
> type
>    TRec = record
>      s1:string;
>      i1:integer;
>    end;
>
> var S1,S2:string;
>      A1,A2:array of integer;
>      R1,R2:TRec;
> begin
>    A1:=[1,2,3];
>    A2:=Copy(A1);
>    A2[0]:=10;
>    writeln(A1[0]);
>    writeln(A2[0]);
>
>    S1:='123';
>    S2:=Copy(S1);
>
>    R1.s1:='123';
>    R1.i1:=1;
>    R2:=Copy(R1);
> end.
> //===========================================
>
> BR,
> Denis
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list