<p dir="ltr">Hi again, </p>
<p dir="ltr">Sven made a good point on records. However most of the time it is easier to use classes. <br>
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 be tricky to cover all cases.</p>
<p dir="ltr">Your proposal on the name/value pair reminds me of Qt but in the Delphi/Fpc world it is done with rtti.</p>
<p dir="ltr">Chriss</p>
<div class="gmail_quote">Στις 28 Δεκ 2014 2:56 π.μ., ο χρήστης "Marc Santhoff" <<a href="mailto:M.Santhoff@web.de">M.Santhoff@web.de</a>> έγραψε:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sa, 2014-12-27 at 19:56 +0200, Chriss Kalogeropoulos wrote:<br>
> Hi,<br>
><br>
> FPC does not support copy-construction so either you must override the<br>
> TPersistent.Assign method or in case of TComponent you can use<br>
> ReadComponent/WriteComponent.<br>
<br>
:|<br>
<br>
> You should also take into account deep vs swallow copy semantics as well as<br>
> the type of the container and contained classes<br>
> (TPersistent/TCmponent/TCollection descendant).<br>
<br>
TCollection is a good idea. Life could be easier if all data container<br>
classes would keep their properties in a name/value hash.<br>
<br>
You're right, looking at the implementation of TPersistent and<br>
TComponent and comparing the overhead to simple data classes is on my<br>
list.<br>
<br>
And of course I'm aware of the shallow copy vs. deep copy problem.<br>
<br>
> For records I am not sure, probably you should need a method on the<br>
> container or check on some internal (compiler magic) functions such as<br>
> CopyRecord and others.<br>
<br>
Currently I'm dealing with records, so there is my first target.<br>
<br>
I feared it would be that way. I think writing an extension for Lazarus<br>
and linking it into the "source" or "refactoring" menu will be a lot<br>
less work, I'll have a deeper look.<br>
<br>
> Hope that helps.<br>
<br>
It does, thank you.<br>
<br>
> Chriss<br>
> On Dec 27, 2014 6:22 PM, "Marc Santhoff" <<a href="mailto:M.Santhoff@web.de">M.Santhoff@web.de</a>> wrote:<br>
><br>
> > On Sa, 2014-12-27 at 16:45 +0100, Bart wrote:<br>
> > > On 12/27/14, Marc Santhoff <<a href="mailto:M.Santhoff@web.de">M.Santhoff@web.de</a>> wrote:<br>
> > ><br>
> > > > function clone(data_in: a_record): a_record;<br>
> > > > var<br>
> > > > data: Pa_record;<br>
> > > > begin<br>
> > > > new(data);<br>
> > > data^ := data_in; //should work*<br>
> > > > end;<br>
> > ><br>
> > > * Might not be a good idea if data contains a class(reference).<br>
> ><br>
> > Oops, I just typed that away and did not hit CTRL-F9 - which is useless<br>
> > in the mailer anyway. ;)<br>
> ><br>
> > --<br>
> > Marc Santhoff <<a href="mailto:M.Santhoff@web.de">M.Santhoff@web.de</a>><br>
> ><br>
> > _______________________________________________<br>
> > fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
> > <a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
> ><br>
> _______________________________________________<br>
> fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
> <a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
<br>
--<br>
Marc Santhoff <<a href="mailto:M.Santhoff@web.de">M.Santhoff@web.de</a>><br>
<br>
_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
</blockquote></div>