[Lazarus] 'with' is evil, isn't it?
Robin Hoo
robin.hoo.cn at gmail.com
Tue Aug 9 03:07:09 CEST 2011
As I see if we could use with like below, adding a dot before
property/function/procedure
with Canvas do
begin
.Rectangle(0, 0, .Width, .Height);
end;
2011/8/5 Alexander Klenin <klenin at gmail.com>
> On Fri, Aug 5, 2011 at 22:04, Luca Olivetti <luca at wetron.es> wrote:
> >> Unfortunately, "with a = b do" is already a valid operator in FPC,
> >> with different meaning.
> >
> > What does it mean?
> >
> > I tried
> >
> > procedure Test;
> > type tr = record
> > f1,f2:integer;
> > end;
> > var r:tr;
> > begin
> > with a=r do;
> > end;
> >
> > and trying to compile it
> > "Error: Operator is not overloaded"
> > "Error: Expression type must be class or record type"
> >
> > Same error even if I define a:tr.
>
> I thought that you could overload opertator =:
>
> type T = record x, y: Integer; end;
> operator =(A, B: T): T; begin Result := a; end;
> var a, b: T;
> begin
> with a = b do Writeln(x);
> end.
>
> However, FPC forbids overloading of "=" with non-Boolean result,
> so it turns out you are right, "=" token is available.
>
> --
> Alexander S. Klenin
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110809/ee10dcef/attachment-0003.html>
More information about the Lazarus
mailing list