<p>Am 28.04.2017 06:06 schrieb "Ryan Joseph" <<a href="mailto:ryan@thealchemistguild.com">ryan@thealchemistguild.com</a>>:<br>
><br>
> Instead of making constructors and doing busy work It would be nice if Free Pascal could let you assign records outside of type blocks like:<br>
><br>
> rec := (x: 0; y: 0; z: 0);<br>
><br>
> Why isn’t this possible btw? I saw some C++ code do this and it seems like an obvious solution that should have existed 20 years ago. The feature exists for type blocks so why not just enable it for other parts of code?</p>
<p>It would introduce an ambiguity as "(x" could also complete to other expressions (e.g. "(x + y) * 2" or even merely "(x)"). Especially older Pascal compilers were geared towards the simplicity of the language and thus they didn't add it. For FPC it simply never came up.</p>
<p>> I had another idea to make this a little simpler by using open arrays and operator overloading. The compiler doesn’t permit this however. Is it a bug, my code or just a limitation?<br>
><br>
> ============<br>
><br>
><br>
> type<br>
> TMyRec = record<br>
> x, y, z: integer;<br>
> class operator Explicit(v: array of integer): TMyRec;<br>
> end;<br>
><br>
> class operator TMyRec.Explicit(v: array of integer): TMyRec;<br>
> begin<br>
> result.x := v[0];<br>
> result.y := v[1];<br>
> result.z := v[2];<br>
> end;<br>
><br>
><br>
> var<br>
> rec: TMyRec;<br>
><br>
> rec := TMyRec([1, 2, 3]); // Illegal type conversion: "Set Of Byte" to "TMyRec"</p>
<p>The compiler currently prefers to cast array constructors towards sets, especially if they contain values that could be expressed as a set. That will change once proper support for array constructors is added. Though I don't know whether this would work then ;)</p>
<p>Regards,<br>
Sven</p>