> What would the expected behavior be for pointers inside records? What if
> the record is actually a linked list? Or includes classes and objects?
> Do we run the constructor or no? If the record has file handles do we
> attempt to recreate their state? (perhaps running assign again, and
> crossin
What would the expected behavior be for pointers inside records? What if
the record is actually a linked list? Or includes classes and objects?
Do we run the constructor or no? If the record has file handles do we
attempt to recreate their state? (perhaps running assign again, and
crossing our
Doing the same conceptual thing using different syntax does not seem right as
generics, macros and other nice stuff become clumsy and too verbose.
See
//
program project1;
{$mode objfpc}
type
TRec= record
A:array of integer;
On Wed, 16 May 2018, denisgolovan wrote:
Yes.
That's exactly why I gave that example.
Your method with Move will trigger segfault eventually, so the compiler support
is required to handle it properly.
But compiler support for copying records exists.
What's wrong with simply doing
R2:=R1;
Yes.
That's exactly why I gave that example.
Your method with Move will trigger segfault eventually, so the compiler support
is required to handle it properly.
BR,
Denis
___
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepasca
I should probably also note that you shouldn't use move with records
that have ansistrings or other dynamically allocated variables in them..
On 5/15/2018 6:49 PM, Alexander Grotewohl wrote:
type
TRec = record
s1:string;
i1:integer;
end;
var
S1,S2:string;
R1,R2:TRec;
begin
S
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 array
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 in
Am 15.05.2018 um 14:15 schrieb denisgolovan:
> A side note:
>
> I am still wondering why there is no something like "Clone" function to make
> an independent copy of string/array/... ? It's used quite often in practice
> (as we don't have copy-on-write working in all circumstances).
There is. I
A side note:
I am still wondering why there is no something like "Clone" function to make an
independent copy of string/array/... ? It's used quite often in practice (as we
don't have copy-on-write working in all circumstances).
BR,
Denis
___
fpc-pasc
On Tue, May 15, 2018 at 12:06 PM, Maciej Izak wrote:
> you can just use :
>
> NewArray := Copy(OldArray);
Mind you, if OldArray is an array of array, Copy() will copy the
reference to the "second" array, not the actal data.
var
a,b: array of array of TSomeType;
SetLength(a, 5, 5);
a[0,0] :=
2018-05-14 11:46 GMT+02:00 Torsten Bonde Christiansen :
> SetLength(NewArray, Length(OldArray));
> for i := Low(OldArray) to High(OldArray) do
> NewArray[i] := OldArray[i];
>
you can just use :
NewArray := Copy(OldArray);
looks better ;)
--
Best regards,
Maciej Izak
Hi List.
This i a real newbie question:
I hardly use dynamic array, so I don't know if there is a simpler method
to copying a dynamic interger array than the straigh forward method:
(I need a copy to preseve the current values of OldArray, since OldArray
will change values later in the progr
13 matches
Mail list logo