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?
Thanks, V.
Mailing lists / fpc-pascal / 2016-06
Type helper for array
5 messages · 3 people · –
- SSven Barth 2
- VVojtěch Čihák 2
- JJürgen Hestermann 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
"Vojtěch Čihák" wrote 27 lines
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
Sven Barth wrote 5 lines
IMO SetLength(aBuffer,0) would the most natural way to clear the array.
"Jürgen Hestermann" wrote 10 lines
*shrugs* That's also a way. Bit the question is whether he want to set the array to empty or if he wants to clear the array's contents without changing the size.
Regards,
Sven
IMO SetLength(aBuffer,0) would the most natural way to clear the array.
@ But the question is whether he want to set the array to empty or if he wants to clear the array's contents without changing the size.
The second is right but it was not the point. "Clear" is just one example of several methods I want to encalupsate into TBuffer. I decided use the type helper now. Another solution is class:
TBuffer = class
Data: array of Single;
procedure Create(ASize: Integer);
procedure Clear;
end;
So I would call aBuffer.Data[3]:=5; instead of aBuffer[3]:=5;. Thanks
______________________________________________________________
Show quoted text 5 lines
"Jürgen Hestermann" < > wrote 10 lines
*shrugs* That's also a way. Bit the question is whether he want to set the array to empty or if he wants to clear the array's contents without changing the size. Regards,
Sven
----------
