[fpc-pascal] Delete and Add for TBytes?

Bo Berglund bo.berglund at gmail.com
Wed Jul 12 21:17:52 CEST 2017


On Wed, 12 Jul 2017 16:26:31 +0200 (CEST), Michael Van Canneyt
<michael at freepascal.org> wrote:

>> Is it possible to overload Delete() so it can be called with TBytes as
>> argument?
>
>It is.
>

OK, then I am doing it erroneously....
(Testing in Delphi XE5 at the moment, but trying to write it to be
portable since the unit that needs this is used both in Delphi and
FPC)

This is how I did it:

In a utility unit "CommonFuncs" normally put into the uses clause of
most source files I added this:

interface
....
// Byte buffer handling 2017-07-12 BB
procedure Delete(var Buf: TBytes; Index, Count: integer); overload;
...
implementation
....
procedure Delete(var Buf: TBytes, Index, Count: integer); overload;
begin
  Move(Buf[Index+Count], Buf[Index], Length(Buf)-Index - Count);
  SetLength(Buf, Length(Buf) - Count);
end;

Then I did a syntax check and it errored out on a line way up in
CommonFuncs (actually the first use of Delete in the implementation
section):

[dcc32 Error] CommonFuncs.pas(357): E2250 There is no overloaded
version of 'Delete' that can be called with these arguments 

The line looks like this:
	Delete(sVal, i, 1);

where sVal is a string, i.e. it should not be affected by the new
Delete since it is not a TBytes variable.

Apparently the System.Delete procedure is missing the "overload"
attribute....

So, what steps do I take in order to "overload" Delete in such a way
that strings will still use the System.Delete?


-- 
Bo Berglund
Developer in Sweden




More information about the fpc-pascal mailing list