[fpc-pascal] Overloading the increment operator (+=)

Flávio Etrusco flavio.etrusco at gmail.com
Tue Sep 13 07:34:59 CEST 2011

On Mon, Sep 12, 2011 at 2:25 AM, Jürgen Hestermann
<juergen.hestermann at gmx.de> wrote:
> Flávio Etrusco schrieb:
>> "+=" can't be efficiently implemented with two operations (since
>> concatenating the operand would be unexpected to the user...).
> Why not use "inc(x,y)"?
> _______________________________________________

AFAICS it's not possible either. (Notice I'm talking about operating
on an 'object').

What I meant is:
    MyStringBuffer += 'String';
Is replaced with:
    MyStringBuffer := MyStringBuffer + 'String';
What if is was:
    MyStringBuffer := OtherStringBuffer + 'String';

So concatenating the 'String' in the StringBuffer's internal buffer
would be unexpected IMO (but maybe just making it safe, even though
unexpected, would be ok).
Also, since the assignment operator for same type can't overload, I
can't make adjustments to avoid "sharing" the buffer so I'm left with
using an AnsiString as buffer, or use some self-pointing canary which
must be checked on every buffer operation.


More information about the fpc-pascal mailing list