[fpc-pascal] Array clearing

Jürgen Hestermann juergen.hestermann at gmx.de
Wed Apr 12 16:43:13 CEST 2017


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 don't see how this can be achieved in a solid and easy to unterstand Array.Fill routine....



More information about the fpc-pascal mailing list