<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2016-07-28 13:30 GMT+02:00 Michael Van Canneyt <span dir="ltr"><<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>></span>:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
Assume a is null before the call to test1:<br>
<br>
test1(a);<br></blockquote><div><br></div><div>That won't compile. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
1. What happens if this procedure is empty, i.e. no write is performed ?<br>
(or it is performed conditionally)<br>
On return, is a null or not ?<br></blockquote><div><br></div><div>You are not able to call test1 in presented form (you will get error: Incompatible types).</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
2. Assume your variable is null before the call to Test1.<br>
What is the value on entry into Test1 ? i.e. what happens if<br>
<br>
begin<br>
if X=0 then<br>
x:=1<br>
else<br>
X:=23;<br>
end<br></blockquote><div><br></div><div>That won't compile too. The correct code:<br></div><div><br></div><div><span style="font-size:12.8px">=== code begin ===</span><br></div><div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px"> if x.HasValue and (x^ = 0) then</span></div><div><span style="font-size:12.8px"> x := 1</span><br></div><div><span style="font-size:12.8px"> else</span></div><div><span style="font-size:12.8px"> x := 23;</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">=== code end ===</span><br></div></div><div><br></div><div>or </div><div><br></div><div><div><span style="font-size:12.8px">=== code begin ===</span><br></div><div><div><span style="font-size:12.8px"> if x.GetValueOrDefault = 0 then</span></div><div><span style="font-size:12.8px"> x := 1</span><br></div><div><span style="font-size:12.8px"> else</span></div><div><span style="font-size:12.8px"> x := 23;</span></div></div><div><span style="font-size:12.8px">=== code end ===</span><br></div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
3. How do you detect an actual write ?<br>
<br>
4. What happens if Test1 is an external C procedure ?</blockquote><div><br></div><div>It depend on context. If we have:</div><div><br></div><div>x := 1; // is detected in class operator Implicit(A: T): TNullable<T>;</div><div><br></div><div>when you use </div><div><br></div><div>x^ := 1; // you are operating directly on Instance field </div><div><br></div><div>in that case if x.HasValue is false you will get <span style="font-size:12.8px">EAccessViolation </span></div><div> </div></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Best regards,<br>Maciej Izak</div></div></div>
</div></div>