<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ryan Joseph <<a href="mailto:genericptr@gmail.com">genericptr@gmail.com</a>> schrieb am Fr., 7. Juni 2019, 14:00:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Jun 7, 2019, at 2:51 AM, Michael Van Canneyt <<a href="mailto:michael@freepascal.org" target="_blank" rel="noreferrer">michael@freepascal.org</a>> wrote:<br>
> <br>
> What kind of behaviour are you referring to.<br>
<br>
Something wrong with my mail server causing your server to block me (Jonas said my server didn’t handle greylisting correctly). Easier to just re-sub using gmail for now.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">Michael meant this: </div><div dir="auto"><span style="color:rgb(128,0,128);font-family:sans-serif;font-size:12.8px">> But my point is Pascal allows this kind of behavior so why are properties</span><br style="color:rgb(128,0,128);font-family:sans-serif;font-size:12.8px"><span style="color:rgb(128,0,128);font-family:sans-serif;font-size:12.8px">> different?</span><br style="color:rgb(128,0,128);font-family:sans-serif;font-size:12.8px"></div><div dir="auto"><span style="color:rgb(128,0,128);font-family:sans-serif;font-size:12.8px"><br></span></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> <br>
>> Who cares if there is an additional level of indirection?<br>
> <br>
> Because the indirection may not be there. The compiler cannot guarantee that, thus leading to access violations.<br>
> <br>
> You can use a getter function to get the desired property. In the getter you<br>
> can decide what to do: create the b instance (sometimes a valid choice) or raise an error.<br>
> <br>
> But the compiler cannot take this decision for you, so b.x is not allowed.<br>
<br>
I really have to question the wisdom of this. The code below works in 3.0.4 and is completely safe. I understand there was delphi compatibility and problems with published properties however but that could have been worked around easily. Maybe it’s a not big deal in the grand scheme of things but writing boiler plate like getters/setters is not fun.<br>
<br>
type<br>
TB = class<br>
x: integer;<br>
end;<br>
<br>
type<br>
TA = class<br>
private<br>
b: TB;<br>
public<br>
property x: integer read b.x write b.x;<br>
procedure AfterConstruction; override;<br>
end;<br>
<br>
<br>
procedure TA.AfterConstruction;<br>
begin<br>
b := TB.Create;<br>
end;<br>
<br>
var<br>
a: TA;<br>
begin<br>
a := TA.Create;<br>
a.x := 100;<br>
writeln(a.x);<br>
end.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Only because this example appears safe does not mean that the whole concept is safe.</div><div dir="auto">A class might initialize b only later on and with a direct property you'll only get an access violation. So you'll need a getter anyway to provide a better exception type. Or to dynamically create the object instance. </div><div dir="auto"><br></div><div dir="auto">I see no reason to revert this change. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div></div>