Recent

Author Topic: Failure to assign record fields via setter  (Read 4679 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Failure to assign record fields via setter
« Reply #15 on: August 25, 2019, 12:45:44 pm »
A compiler enhancement which I am sure does not work in Delphi could really move FPC to the present...
Code: Pascal  [Select][+][-]
  1.  SomeProperty := With SomeOtherProperty do
  2.   begin
  3.     // make all the changes here to the property body given.
  4.    //  do other unrelated things.
  5.   End;
  6.  
That would allow a visible entity to be assigned to a sub entity when the block completes.

 Now that would move FPC to the space age!  :)
No. That is anything, but good language design.

IMHO, a function works just as well and is more readable:

Code: Pascal  [Select][+][-]
  1. function DoSomethingWith(var AProperty: TWhateverType): TSomeOtherType;
  2. begin
  3.   with AProperty do begin
  4.     // make all the changes here to the property body given.
  5.     //  do other unrelated things.
  6.   end;
  7. end;
  8.  
  9.   {... lots of other code ...}
  10.  
  11.   SomeProperty := DoSomethingWith(SomeOtherProperty);

It'll also isolate in the function's body any side-effects the block of code has, which is nice for debugging.
You can not use a var-parameter with a property.

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Failure to assign record fields via setter
« Reply #16 on: August 25, 2019, 08:59:56 pm »
"No. That is anything, but good language design."

 Now why is it I am not surprised with that answer? :(






The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018