Union followed by Property does not compile !

Skybuck Flying <[email protected]> Mon, 1 Aug 2022 09:04:05 -0700 (PDT)
Newsgroups alt.comp.lang.borland-delphi
Message-ID <[email protected]>
program TestProgram;

{$APPTYPE CONSOLE}

{$R *.res}

{

Test program to illustrate the 'union' followed by property problem in Delphi
language

version 0.01 created on 1 august 2022 by Skybuck Flying

There is a problem with "unions" in Delphi language:

When a property follows a "union" declaration it does not compile !

See
TDataExample1 which does compile (no property)
vs
TDataExample2 which does NOT compile (with property)

}

uses
    System.SysUtils;

type
	TDataExample1 = record
	private
		mField : integer;

	public
		// UNION example
		case integer of
			0 : ( mData : int64 );
			1 : ( mByte : packed array[0..7] of byte );

		// DOES COMPILE
	end;

	TDataExample2 = record
	private
		mField : integer;

	public
		// UNION example
		case integer of
			0 : ( mData : int64 );
			1 : ( mByte : packed array[0..7] of byte );

		// !!! DOES NOT COMPILE, PROBLEM !!!
		property Field : integer read mField write mField;
	end;


procedure Main;
begin
	writeln('program started');



	writeln('program finished');
end;

begin
	try
		Main;
	except
		on E: Exception do
			Writeln(E.ClassName, ': ', E.Message);
	end;
	ReadLn;
end.