Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

FluentError

program FluentError;

{$IFDEF FPC}
 {$mode DELPHI} 
{$ELSE}
 {$APPTYPE CONSOLE}
{$ENDIF}

uses
  SysUtils;

type
  Int32 = integer ; //D7

  IFluent = interface
  ['{704F44B3-DC6D-47F0-A12E-3B803FA4BB29}']
      function  GetCol( out ACol : integer ) : IFluent ;
      function  GetRow( out ARow : integer ) : IFluent ;
      function  ShowIntParams(
            const A, B, C, D  : Int32
      ) : IFluent ;
      function  ShowArraysIntParams(
          X, y, z : array of int32
      ) : IFluent ;
      function  NextCol : IFluent  ;
      function  NextRow : IFluent  ;
      function  DebugMsg(const Msg: String)   : IFluent ;
  end ;

  TFluent = class(TInterfacedObject, IFluent )
    private
      FRow,
      FCol : integer ;
      function  DebugMsg(const Msg: String)   : IFluent ;
      function  GetCol( out ACol : integer )  : IFluent ;
      function  GetRow( out ARow : integer )  : IFluent ;
      function  ShowIntParams(
            const A, B, C, D  : Int32
      ) : IFluent ;
      function  ShowArraysIntParams(
           X, y, z : array of int32
      ) : IFluent ;
      function  NextCol  : IFluent ;
      function  NextRow  : IFluent ;
    public
    constructor Create ;
  end;

function TFluent.DebugMsg(const Msg: String) : IFluent ;
begin
    Result := self ;
    WriteLn( msg )
end;

{ TFluent }

function TFluent.GetRow(out ARow: integer): IFluent;
begin
   Result := self ;
   ARow := FRow ;
  DebugMsg( 'getRow( out ' + IntToStr( ARow ) + ')' ) ;
end;

function TFluent.ShowIntParams(
      const A, B, C, D  : Int32
): IFluent;
begin
  DebugMsg(
     'Int Params( '
        + intToStr ( A ) + ', '
        + intToStr ( B ) + ', '
        + intToStr ( C ) + ', '
        + intToStr ( D ) + ')' ) ;

  Result := self ;
end;

function TFluent.ShowArraysIntParams(
          x, y, z : array of int32
      ) : IFluent ;
begin
    
  Result := self ;
  DebugMsg(
    Format (
     'Arrays of Int ('
        + ' X[ %d, %d, %d, %d ]' 
        + ' Y[ %d, %d, %d, %d ]' 
        + ' Z[ %d, %d, %d, %d ]'
        + ' )' 
      , [ 
            x[0], x[1], x[2], x[3] 
          , y[0], y[1], y[2], y[3] 
          , z[0], z[1], z[2], z[3] 
         ] 
    )
  ) ;    
end;


function TFluent.GetCol(out ACol: integer): IFluent;
begin
  Result := self ;
  ACol := FCol ;
  DebugMsg( 'getCol( out ' + IntToStr ( ACol ) + ')' ) ;
end;

function  TFluent.NextCol : IFluent ;
begin
  Result := self ;
  Inc ( FCol ) ;
  DebugMsg( 'NextCol : ' + IntToStr(FCol - 1) +  ' -> ' + IntToStr(FCol)  ) ;
end;

function  TFluent.NextRow : IFluent ;
begin
  Result := self ;
  Inc ( FRow ) ;
  DebugMsg( 'NextRow : ' + IntToStr(FRow - 1) +  ' -> ' + IntToStr(FRow)  ) ;
end;

constructor TFluent.Create;
begin
  FRow := 0 ;
  FCol := 0 ;
end;

var
  LRow1, LCol1, LRow2, LCol2 : integer ;
  LFluent: IFluent ;
begin
  LFluent := TFluent.Create ;

  LRow1 := -1 ;
  LCol1 := -1 ;
  LRow2 := -1 ;
  LCol2 := -1 ;

  LFluent
    .DebugMsg ( 'InitValues' )
    .NextRow
    .GetRow ( LRow1 )
    .NextRow
    .GetRow ( LRow2 )
    .NextCol
    .GetCol ( LCol1 )
    .NextCol
    .GetCol ( LCol2 )
    .DebugMsg ( 'Show values (wrong values in delphi compilers)' )
    .ShowIntParams( LRow1, LCol1, LRow2, LCol2 )
    .ShowIntParams( LRow2, LCol2, LRow1, LCol1 )
    .ShowIntParams( LRow1, LCol2, LRow2, LCol1 )
    .ShowIntParams( LRow1, LCol2, LRow1 + 10, LCol2 + 10 )
    .ShowArraysIntParams( {X} [LRow1, LCol1, LRow2, LCol2],
                          {Y} [LRow1, LCol1, LRow2, LCol2],
                          {Z} [LRow1, LCol1, LRow2, LCol2] )
    .ShowArraysIntParams( {X} [LRow2, LCol2, LRow1, LCol1],
                          {Y} [LRow1, LCol1, LRow2, LCol2],
                          {Z} [LRow1, LCol1, LRow2, LCol2] )
    .ShowArraysIntParams( {X} [LRow1, LCol2, LRow2, LCol1],
                          {Y} [LRow1, LCol1, LRow2, LCol2],
                          {Z} [LRow1, LCol1, LRow2, LCol2] )
    .DebugMsg ( 'Press [enter]' )
  ;

  ReadLn ;

  LFluent
    .DebugMsg ( 'Show values (correct values in delphi compilers)' )
    .ShowIntParams( LRow1, LCol1, LRow2, LCol2 )
    .ShowIntParams( LRow2, LCol2, LRow1, LCol1 )
    .ShowIntParams( LRow1, LCol2, LRow2, LCol1 )
    .ShowIntParams( LRow1, LCol2, LRow1 + 10, LCol2 + 10 )
    .ShowArraysIntParams( {X} [LRow1, LCol1, LRow2, LCol2],
                          {Y} [LRow1, LCol1, LRow2, LCol2],
                          {Z} [LRow1, LCol1, LRow2, LCol2] )
    .ShowArraysIntParams( {X} [LRow2, LCol2, LRow1, LCol1],
                          {Y} [LRow1, LCol1, LRow2, LCol2],
                          {Z} [LRow1, LCol1, LRow2, LCol2] )
    .ShowArraysIntParams( {X} [LRow1, LCol2, LRow2, LCol1],
                          {Y} [LRow1, LCol1, LRow2, LCol2],
                          {Z} [LRow1, LCol1, LRow2, LCol2] )
    .DebugMsg ( 'Press [enter]' )
  ;

  ReadLn ;
end.

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.