Cari Blog Ini

Jumat, 03 Desember 2010

delphi repeated 1-10






Created with Delphi 7 by Avid/Kira
Form ‘perulangan angka’


Sintak:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    Memo2: TMemo;
    Memo3: TMemo;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var x:integer;
begin
  if ((sender as tbutton).tag=1) then
  for x:=1 to 10 do
  memo1.lines.add(inttostr(x))
  else
  if ((sender as tbutton).tag=2) then
begin
  x:=1;
  repeat
  memo2.lines.add(inttostr(x));
  inc(x);
  until x>10;
  end
  else if ((sender as tbutton).tag=3) then
  begin
  x:=1;
  while (x<=10) do
  begin
  memo3.lines.add(inttostr(x));
  inc(x);
  end;
end;
{
begin
case (sender as tbutton).tag of
1:for x:=1 to 10 do
  memo1.lines.add(inttostr(x));
2:begin
  x:=1;
  repeat
  memo2.lines.add(inttostr(x));
  inc(x);
  until x>=10;
  end;
3:begin
  x:=1;
  while (x:=10) do
  begin
  memo3.lines.add(inttostr(x));
  inc(x);
  end;
  end;
  end;
}
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
application.Terminate;
end;

end.

Tidak ada komentar:

Posting Komentar