unit1.pas

来自「Componente Delphi para Array」· PAS 代码 · 共 61 行

PAS
61
字号
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  num: array[1..20] of integer;
  aux, fim, ini, pri, seg: integer;
  i, i2, tot: integer;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
   i := i+1;
   num[i] := StrToInt(Edit1.Text);
   StringGrid1.Cells[0,i-1] := inttostr(num[i]);
   Edit1.Clear;
   Edit1.Setfocus;
   tot := i;
   Label1.Caption := 'Total: ' + IntToStr(tot);

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
   for i:= 1 to tot-1 do
         for i2 := i+1 to tot do
               if num[i] > num[i2] then begin
                     aux := num[i];
                     num[i] := num[i2];
                     num[i2] := aux;
               end;
//coloca no grid
   for i := 1 to tot do
       StringGrid1.Cells[0,(i-1)] := IntToStr(num[i]);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?