2018-11-26 for in 循环 数组 XE

unit Unit3;

interface

uses

  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type

  TForm3 = class(TForm)

    Button1: TButton;

    Memo1: TMemo;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

var

  Form3: TForm3;

  a1:array [1..5] of integer=(1,2,37,4,8);  //数组赋值5个就是5个,不能多也不能少

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);

var

  i:integer;

begin

  for i in a1 do

Memo1.Lines.Add(inttostr(i));

  end;

end.


__________________________________________________

unit Unit3;

interface

uses

  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type

    Tarray= array [1..5] of integer;

  TForm3 = class(TForm)

    Button1: TButton;

    Memo1: TMemo;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

{

var

  Form3: TForm3;

const

a1:array [1..5] of integer=(1,2,37,4,8);

  }

  var

  Form3: TForm3;

  a1:array [1..5] of integer=(1,2,37,4,8);

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);

var

  i:integer;

begin

  for i in a1 do

Memo1.Lines.Add(inttostr(i));

  end;

end.

____________________________________________________

unit Unit3;

interface

uses

  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type

    Tarray= array [1..5] of integer;

  TForm3 = class(TForm)

    Button1: TButton;

    Memo1: TMemo;

    Memo2: TMemo;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

{

var

  Form3: TForm3;

const

a1:array [1..5] of integer=(1,2,37,4,8);

  }

  var

  Form3: TForm3;

  a1:Tarray;

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);

var

  i,m:integer;

begin

    for i := 0 to 4 do

    a1[i+1]:= strtoint(memo2.Lines[i]); //在memo2中放入1,2,37,4,8  并将其赋值到a1数组内

    for m in a1 do

  Memo1.Lines.Add(inttostr(m));

    end;

end.

---------------------------------------------------------------------------------------

unit Unit3;

interface

uses

  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type

    Tarray= array [1..5] of string;

  TForm3 = class(TForm)

    Button1: TButton;

    Memo1: TMemo;

    Memo2: TMemo;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

{

var

  Form3: TForm3;

const

a1:array [1..5] of integer=(1,2,37,4,8);

  }

  var

  Form3: TForm3;

  a1:Tarray;

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);

var

  i:integer;

  m:string;

begin

    for i := 0 to 4 do

    a1[i+1]:= memo2.Lines[i];  //在memo2中放入a,d,f,k,p 并将其赋值到a1数组内

    for m in a1 do

  Memo1.Lines.Add(m);

    end;

end.

-________________________________________________________________

unit Unit3;

interface

uses

  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type

    Tarray= array of string;

  TForm3 = class(TForm)

    Button1: TButton;

    Memo1: TMemo;

    Memo2: TMemo;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

  var

  Form3: TForm3;

  a1:Tarray;

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);

var

  i:integer;

  m:string;

begin

  setlength(a1,16);    //开辟数组空间

    for i := 0 to 4 do

    a1[i+1]:= pchar(memo2.Lines[i]);  //在memo2中放入a,d,f,k,p 并将其赋值到a1数组内

    for m in a1 do

  Memo1.Lines.Add(m);

    end;

end.

你可能感兴趣的:(2018-11-26 for in 循环 数组 XE)