Re: [fpc-pascal] cloning data containers

2014-12-27 Thread Marc Santhoff
On So, 2014-12-28 at 03:08 +0200, Chriss Kalogeropoulos wrote: > Hi again, > > Sven made a good point on records. However most of the time it is easier to It took me some time to understand, he did actually. > use classes. Not possible on old code, new stuff is using objects for sure. > Also y

Re: [fpc-pascal] cloning data containers

2014-12-27 Thread Marc Santhoff
On So, 2014-12-28 at 00:01 +0100, Sven Barth wrote: > Am 27.12.2014 16:11 schrieb "Marc Santhoff" : > > Is there any way of cloning record and objects having only data fields? > > Or do I have to copy the (non reference) fields one by one as usual? > > Shouldn't the normal assignment be enough for

Re: [fpc-pascal] cloning data containers

2014-12-27 Thread Chriss Kalogeropoulos
Hi again, Sven made a good point on records. However most of the time it is easier to use classes. Also you might be able to write some code to copy the property values using rtti so you can avoid the read/write component and the extra overhead. It will work for TPersistent descendants but might b

Re: [fpc-pascal] cloning data containers

2014-12-27 Thread Marc Santhoff
On Sa, 2014-12-27 at 19:56 +0200, Chriss Kalogeropoulos wrote: > Hi, > > FPC does not support copy-construction so either you must override the > TPersistent.Assign method or in case of TComponent you can use > ReadComponent/WriteComponent. :| > You should also take into account deep vs swallow

Re: [fpc-pascal] cloning data containers

2014-12-27 Thread Sven Barth
Am 27.12.2014 16:11 schrieb "Marc Santhoff" : > Is there any way of cloning record and objects having only data fields? > Or do I have to copy the (non reference) fields one by one as usual? Shouldn't the normal assignment be enough for any non-reference (aka non-managed pointers) fields? Meaning

Re: [fpc-pascal] cloning data containers

2014-12-27 Thread Chriss Kalogeropoulos
Hi, FPC does not support copy-construction so either you must override the TPersistent.Assign method or in case of TComponent you can use ReadComponent/WriteComponent. You should also take into account deep vs swallow copy semantics as well as the type of the container and contained classes (TPer

Re: [fpc-pascal] cloning data containers

2014-12-27 Thread Marc Santhoff
On Sa, 2014-12-27 at 16:45 +0100, Bart wrote: > On 12/27/14, Marc Santhoff wrote: > > > function clone(data_in: a_record): a_record; > > var > > data: Pa_record; > > begin > > new(data); > data^ := data_in; //should work* > > end; > > * Might not be a good idea if data contains a class

Re: [fpc-pascal] cloning data containers

2014-12-27 Thread Bart
On 12/27/14, Marc Santhoff wrote: > function clone(data_in: a_record): a_record; > var > data: Pa_record; > begin > new(data); data^ := data_in; //should work* > end; * Might not be a good idea if data contains a class(reference). Bart ___ f

[fpc-pascal] cloning data containers

2014-12-27 Thread Marc Santhoff
Hi, I hope you all had nice christmas days and now can answer my question. ;) Is there any way of cloning record and objects having only data fields? Or do I have to copy the (non reference) fields one by one as usual? Explanation: a_record = record this: integer; that: string; ... end f