[Lazarus] Extending TRect breaks Lazarus

Ondrej Pokorny lazarus at kluug.net
Sat Nov 7 06:42:14 CET 2015

On 06.11.2015 22:45, Mark Morgan Lloyd wrote:
> Luca Olivetti wrote:
>>  with a=somerecord, b=someotherrecord do
>>  begin
>>    a.x:=b.x;
>>  end;
> Just because something is 20+ years old doesn't necessarily make it 
> bad. That syntax looks OK to me (i.e. make a and b look like consts) 
> but I also find myself wondering what the type rules are, i.e.
> with pod: TTabSheet= Pages.Objects[deleteAt] do
> vs
> with pod= TTabSheet(Pages.Objects[deleteAt]) do

Do not forget that you can overload operators! In particular you can 
overload the comparison operator to return a record, so your
"with a=somerecord do" can already be a valid pascal code now:

**  TMyRec = record**
**    I: Integer;**
**  end;**
**  TMyResult = record**
**    Res: Integer;**
**  end;**
**operator = (z1: TMyRec; z2 : TMyRec) b : TMyResult;**
**  Result.Res := z1.I+z2.I;**
**  m1, m2: TMyRec;**
**  m1.I := 10;**
**  m2.I := 1;**
**  with m1=m2 do**
**    writeln(Res);**
**  readln;**

The assignment operator would be better, since it doesn't return a value 
(in pascal, of course) and thus cannot be used in a with statement now:

*with a:=somerecord, b:=someotherrecord do**
**  a.x:=b.x;**
**end; **
IMO there is no need to set a type of a/b on the left side of the with 
assignment - the left side should always gain the type from the the 
right side. In this case you can decide whether the "AS" or the direct 
re-type should be used:

*with pod := Pages.Objects[deleteAt] as TTabSheet do **
**with pod := TTabSheet(Pages.Objects[deleteAt]) do **
-> both are valid and the syntax is already in pascal - why not to use it.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20151107/fb06130b/attachment-0003.html>

More information about the Lazarus mailing list