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:

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

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**
**begin**
**  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.

Ondrej
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to