[fpc-pascal] How can I implement "thrice" in Free Pascal?

Sven Barth pascaldragon at googlemail.com
Wed Oct 19 08:27:30 CEST 2011


Am 18.10.2011 21:59, schrieb Jonas Maebe:
>
> On 18 Oct 2011, at 21:55, Sven Barth wrote:
>
>>
>> type
>>   TGenArray<T>  = array of T; // this should work in trunk already
>>
>> function Concat<T>(Arr1, Arr2: TGenArray<T>): TGenArray<T>;
>> begin
>>   SetLength(Result, Length(aArray1) + Length(aArray2));
>>   if Length(aArray1)>  0 then
>>     Move(aArray1[0], Result[0], Length(aArray1) * SizeOf(T));
>>   if Length(aArray2)>  0 then
>>     Move(aArray2[0], Result[Length(aArray1)], Length(aArray2) * SizeOf(T));
>> end;
>
> This implementation will result in crashes if T is a reference-counted type.

Right... I tend to forget about these... what would the correct way to 
copy an array of ref counted types? E.g. an "array of string"?

Regards,
Sven




More information about the fpc-pascal mailing list