<div dir="auto"><div><div class="gmail_quote"><div dir="ltr">Michael Van Canneyt <<a href="mailto:michael@freepascal.org">michael@freepascal.org</a>> schrieb am Fr., 25. Mai 2018, 10:15:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On Fri, 25 May 2018, Sven Barth via fpc-pascal wrote:<br>
<br>
> Yes, that is what it does. Though a possible optimization would be that the<br>
> compiler detects "dynarr := dynarr + [elem]" and converts it to<br>
> "Insert(elem, dynarr, High(dynarr))".<br>
><br>
><br>
>> Since dynamic array helpers work could you expose a function that adds an<br>
>> element to the array (an grows it if needed) so we could make helpers for<br>
>> it? Pushing a value to an array is perhaps the most common function used<br>
>> for lists so it makes sense to get that right imo.<br>
>><br>
><br>
> That function already exists and is called Insert() (see above).<br>
<br>
Nice. I didn't know Insert() could be used to append to the end of a string.<br>
<br>
One learns every day ! One for the documentation :-)<br>
<br>
To be clear: for strings you can do<br>
<br>
var<br>
S : String;<br>
<br>
begin<br>
S:='123';<br>
Insert('456',S,Length(S)+2);<br>
Writeln(S);<br>
end.<br>
<br>
and it will append. Is the same true for dynamic arrays ? <br>
i.e. any insert position >= length will do an append ?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Correct :) </div><div dir="auto"><br></div><div dir="auto">Similar for indices <= 0: they will always prepend (for strings <= 1 of course). </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>