[fpc-pascal] Dynamic array as result of class method?
bo.berglund at gmail.com
Sun Nov 7 11:05:21 CET 2010
I am trying to design a buffer handling class where I want to have a
read function, which should return a result in the form of a byte
array of varying length. Something like this:
TBufHandler = class
FBuf: array of byte;
function GetLength: Cardinal;
constructor Create(Size: Cardinal);
destructor Destroy; override;
property DataLength: Cardinal read GetLength;
function Write(Source: Pointer; Count: Cardinal): boolean;
function Read(Dest: Pointer; Count: Cardinal): Cardinal; overload;
function Read(Count: Cardinal): array of byte; overload;
Here I will create the FBuf dynamic array in the constructor and set
it to the length specified by the parameter Size.
The two overloaded Read methods both return data from the FBuf array
where the second one is supposed to work as follows:
- Check if there are Count bytes available from the ReadIndex to the
- Use the smaller of Count and that difference.
- Set the length of Result accordingly
- Copy/Move data from FBuf into Result
But when I use the Ctrl-Shift-C command on this to make Lazarus
complete the code I get an error on the second Read line:
sscomm.pas(40,37) Error: identifier expected, but array found
Is it illegal to specify a dynamic array as the result type of a
If so why is it possible to use the string type as a function result,
a string is also dynamically sized inside the function??
Or is this a Lazarus implementation problem rather than a FPC problem?
More information about the fpc-pascal