■3.2 演習その1:社長命令・起立!

実行例

 

D:\ObjectNou\3-2>Shacho3_2.exe Tanto
担当が普通に起立します

D:\ObjectNou\3-2>Shacho3_2.exe Shunin
主任がすばやく立ちました

D:\ObjectNou\3-2>Shacho3_2.exe Bucho
部長がだるそうに立ちました

 

↑Top

Shacho3_2.dpr

program Shacho3_2;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  UnitShain in 'UnitShain.pas',
  UnitShunin in 'UnitShunin.pas',
  UnitTanto in 'UnitTanto.pas',
  UnitTorishimariyaku in '..\3-4\UnitTorishimariyaku.pas';

var
  Shain : TShain;
begin
  try
    Shain := nil;
    try
      if ParamCount > 0 then
      begin
        if ParamStr(1) = 'Tanto' then
          Shain := TTanto.Create
        else if ParamStr(1) = 'Shunin' then
          Shain := TShunin.Create
        else if ParamStr(1) = 'Bucho' then
          Shain := TBucho.Create
        else
          raise Exception.Create('役職エラー');
      end
      else
        raise Exception.Create('役職エラー');

      Shain.Standup;
    finally
      Shain.Free;
    end;
  except on E:exception do
    Writeln(E.message);
  end;

end.

↑Top

UnitShain.pas

unit UnitShain;

interface

type
  TShain = class(TObject)
  private
    { Private 宣言 }
  public
    { Public 宣言 }
    constructor Create; 
    procedure Standup; virtual; abstract;
  end;

implementation

{ TShain }

constructor TShain.Create;
begin
//
end;

end.

↑Top

UnitTanto.pas

unit UnitTanto;

interface

uses
  UnitShain;

type
  TTanto = class(TShain)
  private
    { Private 宣言 }
  public
    { Public 宣言 }
    procedure Standup; override;
  end;
implementation { TTanto } procedure TTanto.Standup; begin Writeln('担当が普通に起立します'); end; end.

↑Top

UnitShunin.pas

unit UnitShunin;

interface

uses
  UnitShain;

type
  TShunin = class(TShain)
  private
    { Private 宣言 }
  public
    { Public 宣言 }
    procedure Standup; override;
  end;
implementation
{ TShunin }
procedure TShunin.Standup; begin Writeln('主任がすばやく立ちました'); end; end.

↑Top

UnitBucho.pas

unit UnitBucho;

interface

uses
  UnitShain;

type
  TBucho = class(TShain)
  private
    { Private 宣言 }
  public
    { Public 宣言 }
    procedure Standup; override;
  end;
implementation
{ TBucho }
procedure TBucho.Standup; begin Writeln('部長がだるそうに立ちました'); end; end.

↑Top

目次前へ次へ