<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">
program TestProgram3;</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">
{
<div><br>
</div>
<div>Test program to illustrate the 'union' followed by property problem in Delphi</div>
<div>language and Free Pascal Language<br>
</div>
<div><br>
</div>
<div>version 0.01 created on 1 august 2022 by Skybuck Flying</div>
<div><br>
</div>
<div>There is a problem with "unions" in Delphi language:</div>
<div><br>
</div>
<div>When a property follows a "union" declaration it does not compile !</div>
<div><br>
</div>
<div>See</div>
<div>TDataExample1 which does compile (no property)</div>
<div>vs</div>
<div>TDataExample2 which does NOT compile (with property)</div>
<div><br>
</div>
}<br>
<div><br>
</div>
<div>{$mode objfpc}{$H+}</div>
<div><br>
</div>
<div>uses</div>
<div> {$IFDEF UNIX}</div>
<div> cthreads,</div>
<div> {$ENDIF}</div>
<div> Classes, SysUtils, CustApp</div>
<div> { you can add units after this };</div>
<div><br>
</div>
<div>type</div>
<div><br>
</div>
<div> { TMyApplication }</div>
<div><br>
</div>
<div> TMyApplication = class(TCustomApplication)</div>
<div> protected</div>
<div> procedure DoRun; override;</div>
<div> public</div>
<div> constructor Create(TheOwner: TComponent); override;</div>
<div> destructor Destroy; override;</div>
<div> procedure WriteHelp; virtual;</div>
<div> end;</div>
<div><br>
</div>
<div>{ TMyApplication }</div>
<div><br>
</div>
<div>type</div>
<div> TDataExample1 = record</div>
<div> mField : integer;</div>
<div><br>
</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>
<div> end;</div>
<div><br>
</div>
<div> TDataExample2 = record</div>
<div> mField : integer;</div>
<div><br>
</div>
<div><br>
</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 NOT COMPILE, PROBLEM !!!</div>
<div> property Field : integer read mField write mField;</div>
<div> end;</div>
<div><br>
</div>
<div>procedure TMyApplication.DoRun;</div>
<div>var</div>
<div> ErrorMsg: String;</div>
<div>begin</div>
<div> // quick check parameters</div>
<div> ErrorMsg:=CheckOptions('h', 'help');</div>
<div> if ErrorMsg<>'' then begin</div>
<div> ShowException(Exception.Create(ErrorMsg));</div>
<div> Terminate;</div>
<div> Exit;</div>
<div> end;</div>
<div><br>
</div>
<div> // parse parameters</div>
<div> if HasOption('h', 'help') then begin</div>
<div> WriteHelp;</div>
<div> Terminate;</div>
<div> Exit;</div>
<div> end;</div>
<div><br>
</div>
<div> { add your program here }</div>
<div><br>
</div>
<div> // stop program loop</div>
<div> Terminate;</div>
<div>end;</div>
<div><br>
</div>
<div>constructor TMyApplication.Create(TheOwner: TComponent);</div>
<div>begin</div>
<div> inherited Create(TheOwner);</div>
<div> StopOnException:=True;</div>
<div>end;</div>
<div><br>
</div>
<div>destructor TMyApplication.Destroy;</div>
<div>begin</div>
<div> inherited Destroy;</div>
<div>end;</div>
<div><br>
</div>
<div>procedure TMyApplication.WriteHelp;</div>
<div>begin</div>
<div> { add your help code here }</div>
<div> writeln('Usage: ', ExeName, ' -h');</div>
<div>end;</div>
<div><br>
</div>
<div>var</div>
<div> Application: TMyApplication;</div>
<div>begin</div>
<div> Application:=TMyApplication.Create(nil);</div>
<div> Application.Title:='My Application';</div>
<div> Application.Run;</div>
<div> Application.Free;</div>
<div>end.</div>
<br>
</div>
</body>
</html>