<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Delphi and presumably Free Pascal has some language inconsistency and problem/short coming concerning "Union Field" and/or "Union Property":<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
The (previous) presented solution (included at end of post) is inconsistent in two ways:
<div><br>
</div>
<div>1. Property of union not possible.</div>
<div><br>
</div>
<div>2. Order of field and property violations "field before property" rule.</div>
<div><br>
</div>
<div>(Both problems demonstrated in TDataExample3)<br>
</div>
<div><br>
</div>
<div>{</div>
<div><br>
</div>
<div>version 0.03 created on 14 august 2022 by Skybuck Flying:</div>
<div><br>
</div>
<div>Today I remember the rule which this union field is conflicting with.</div>
<div><br>
</div>
<div>The rule: "field before property"</div>
<div><br>
</div>
<div>Going to demonstrate it below</div>
<div><br>
</div>
<div>There are apperently two problems with this solution:</div>
<div><br>
</div>
<div>1. Property of union not possible ?!?</div>
<div><br>
</div>
<div>2. Inconsistent language design in respect to standard field + property relation</div>
<div>(order of appearance/declaration)</div>
<div><br>
</div>
<div>// ERROR "field definition not allowed after methods or properties" problem 2.</div>
<div><br>
</div>
<div>}</div>
<div><br>
</div>
<div><br>
</div>
<div>type</div>
<div> TDataExample3 = record</div>
<div><br>
</div>
<div>// mStandardField : integer; // OK</div>
<div><br>
</div>
<div> // normal/standard property</div>
<div> property StandardField : integer read mStandardField write mStandardField;</div>
<div><br>
</div>
<div> mStandardField : integer; // ERROR "field definition not allowed after methods or properties" problem 2.</div>
<div><br>
</div>
<div><br>
</div>
<div> // union property</div>
<div>// property UnionField : int64 read mData write mData; // not possible, problem 1</div>
<div><br>
</div>
<div> // union fields</div>
<div> case integer of // INCONSISTENT problem 2</div>
<div> 0 : ( mData : int64 );</div>
<div> 1 : ( mByte : packed array[0..7] of byte );</div>
<div><br>
</div>
<div>// property UnionField : int64 read mData write mData; // not possible, problem 1</div>
<div><br>
</div>
<div> end;</div>
<div><br>
</div>
<div><br>
</div>
<div>The original problem was:</div>
<div><br>
</div>
<div>(*
<div> // ORIGINAL PROBLEM:</div>
<div> TDataExample0 = record</div>
<div> private</div>
<div> mField : integer;</div>
<div> public</div>
<div> // UNION example</div>
<div> case integer of</div>
<div> 0 : ( mData : int64 );</div>
<div> 1 : ( mByte : packed array[0..7] of byte );</div>
<div><br>
</div>
<div> property Field read mField write mField; // DOES NOT COMPILE.</div>
<div> end;</div>
<div>*)</div>
<br>
</div>
<div><span> </span>// UNION DECLARATION example that does work without properties, just to check"<br>
</div>
<div><br>
</div>
<div> TDataExample1 = record
<div> private</div>
<div> mField : integer;</div>
<div><br>
</div>
<div> public</div>
<div> // UNION example</div>
<div> case integer of</div>
<div> 0 : ( mData : int64 );</div>
<div> 1 : ( mByte : packed array[0..7] of byte );</div>
<div><br>
</div>
<div> // DOES COMPILE</div>
end;<br>
</div>
<div><br>
</div>
<div>Presented solution for union field in record with properties was:</div>
<div><br>
</div>
<div> TDataExample2 = record
<div> private</div>
<div> mField : integer;</div>
<div><br>
</div>
<div> public</div>
<div> // SOLUTION:</div>
<div> property Field : integer read mField write mField;</div>
<div><br>
</div>
// PUT CASE STATEMENT LAST
<div> case integer of</div>
<div> 0 : ( mData : int64 );</div>
<div> 1 : ( mByte : packed array[0..7] of byte );</div>
<div><br>
</div>
end;<br>
</div>
<div><br>
</div>
<div>Bye,</div>
Skybuck.<br>
</div>
</body>
</html>