5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FizzBuzzAdvent Calendar 2017

Day 9

DelphiのFiremonkeyでFizzBuzzをやってみた

Last updated at Posted at 2017-11-08

#DelphiのFiremonkeyでFizzBuzzをやってみた

ことのほったんはTwitter上でフォロワーさんの @pik さんがdelphiで最小文字数でFizzBuzzを作ったというのを見てなんとなくどう動くのか実際に実行したらコマンドプロンプトが一瞬で消えたのでフォーム上で確認したくなり作ってみた

出来上がりイメージをフォームにて開始と終了の数値を入力できてボタンを押せば実行されて、フォーム画面上で結果を確認できるようなものを想定し作成しました

Delphiなので1つのソースファイルでWinでもMacでも動きます

Win7版スクリーンショット
Win7_p1.jpg

MacOSX版スクリーンショット
MacX_p1.png

ソースコード

p.pas

unit p;
interface
uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, FMX.Layouts,
  FMX.Memo, FMX.Edit;
type
  Tf = class(TForm)
    b: TButton;
    L1: TLabel;
    L2: TLabel;
    e1: TEdit;
    e2: TEdit;
    m: TMemo;
    procedure bClick(Sender: TObject);
  private
  public
  end;
var
  f: Tf;
implementation
{$R *.fmx}
procedure Tf.bClick(Sender: TObject);
var
  i: Integer;
  s: String;
begin
  for i := e1.Text.ToInteger to e2.Text.ToInteger do
  begin
    s := '';
    if (i mod 3 = 0) then
    begin
      s := 'Fizz';
    end;
    if (i mod 5 = 0) then
    begin
      s := s + 'Buzz';
    end;
    if (s = '') then
    begin
      s := i.ToString;
    end;
    m.Text := m.Text + s + #13#10;
  end;
end;
end.

5
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?