[fpc-pascal] Type helper for array

Sven Barth pascaldragon at googlemail.com
Thu Jun 9 20:18:04 CEST 2016


Am 09.06.2016 17:57 schrieb "Vojtěch Čihák" <vojtech.cihak at atlas.cz>:
>
> Hello,
>
> I've got following declaration:
> ...
> {$modeswitch typehelpers}
>
> interface
>
> uses
>   Classes, SysUtils;
>
> type
>   TBuffer = array of Single;
>
>   { TBufferHelper }
>   TBufferHelper = type helper for TBuffer
>     procedure Clear;
>   end;
> ...
> var aBuffer: TBuffer;
> ...
> And I can do:
> aBuffer[3]:=5;
> aBuffer.Clear;
>
> Is it possible to do this without helper? Since it's IMO silly to have
helper in the same unit as the original declaration. Helpers are usually
used where extending of the original type is not possible, aren't they?

You can always set the array to Nil or use FillChar(), depending on what
you want to achieve with Clear. You can also put the helper in another unit
if you want, it doesn't need to be in the same as the type it extends.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160609/681c1778/attachment.html>


More information about the fpc-pascal mailing list