Unit SetGetSub;

interface
// global part

{ $W+}                  // enable/disable warnings for this unit

uses ;

{--------------------------------------------------------------}
{ Const Declarations }
const

{$IDATA}
{--------------------------------------------------------------}
{ Type Declarations }
type

{--------------------------------------------------------------}
{ Var Declarations }
var

{--------------------------------------------------------------}
{ functions }
procedure Set4x2( NewVal : byte ); // Setter
function Get4x2 : byte; // getter
procedure Set5x2( NewVal : byte ); // Setter
function Get5xc2 : byte; // getter


implementation
// local part

{--------------------------------------------------------------}
{ Type Declarations }
type

{--------------------------------------------------------------}
{ Const Declarations }
const

{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
  x2 : byte;
  xc2 : byte;
  
{--------------------------------------------------------------}
{ functions }

//---------------------- Try 4

procedure Set4x2( NewVal : byte ); // Setter
begin
  x2 := NewVal;
  {
     Note that this becomes an inline function, keeping control but without impacting on code size
  }
end;

function Get4x2 : byte; // getter
begin
  return( x2 );
  {
     Note that this becomes an inline function, keeping control but without impacting on code size
  }
end;

//----------------------- Try 5

procedure Set5x2( NewVal : byte );
begin
{
  here we are 'doing the right thing'. We keep a count of every time we
  assign a value. This function is no longer inline
}
  x2 := NewVal;
  inc( xc2 );
end;

function Get5xc2 : byte;
var
  Result : byte;
begin
{
  this getter for xc2 automatically resets the count.
  This will not be inline
}
  Result := xc2;
  xc2 := 0;
  return( Result );
end;


initialization
// at StartUp

// finalization          // optional
// at System_ShutDown
end SetGetSub.

