[fpc-pascal] Array clearing

Michael Van Canneyt michael at freepascal.org
Wed Apr 12 16:47:30 CEST 2017



On Wed, 12 Apr 2017, Jürgen Hestermann wrote:

> Am 2017-04-12 um 16:17 schrieb Ryan Joseph:
> > SetLength resizes the array in memory and “clear” means setting all values 
> to default() for that type.
>
> "clear" is not very clear to me ;-)
> IMO SetLength(array,0) is clearing too.
>
> The function you want should be called "Fill".
> For example a function
>
> Array.Fill(DefaultValue);
>
> But what happens to a multi-dimensional (dynamic) array?
> For example, how to handle this case:
>
> Type MyType = record
>               A : Integer;
>               B : array of char;
>               C : array of Float;
>               end; // of record
>      ArrayA = array of MyType;
>      ArrayB = array of ArrayA.
>
> What would be the DefaultValue for
>
> ArrayB.Fill(DefaultValue);
>
> ?

I would think Nil is the only option here,  ArrayB is an array of arrays

Michael.


More information about the fpc-pascal mailing list