学習構造[レコード]タイプ(1)-開始

1237 ワード


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// ,  :
procedure TForm1.Button1Click(Sender: TObject);
var
  name: string;
  age: Word;
begin
  { }
  name := ' ';
  age := 18;

  { }
  ShowMessage(Format('%s %d ', [name,age])); { 18 }
end;


// 
procedure TForm1.Button2Click(Sender: TObject);
type
  TPerson = record
    name: string[12]; { }
    age: Word;
  end;
var
  person: TPerson;        { }
const
  str = '%s %d ';     { }
begin
  { }
  person.name := ' ';
  person.age := 81;

  { }
  ShowMessage(Format(str, [person.name,person.age])); { 81 }
end;

end.