📄 unit1.~pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Edit4: TEdit;
Label5: TLabel;
Edit5: TEdit;
Label6: TLabel;
Edit6: TEdit;
Label7: TLabel;
Edit7: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
a :array [1..7] of integer;
i,k,j,tmp: integer;
s: string;
begin
randomize;
// m:=1+random(36);
// s:=inttostr(m);
// Edit1.Text:=s;
{a[7]:=1;
while a[7]<>36 do
a[7]:=1+random(36);
edit7.Text:= inttostr(a[7]);}
////////////////////////////////
//下面是获取不相等的7个数字。//
////////////////////////////////
a[1] := 1+random(36);
for j:=2 to 7 do
begin
a[j]:=1+random(36);
// s:=inttostr(a[j]);
for k:=1 to j-1 do
while a[j]=a[k] do
a[j]:=1+random(36);
//这样的循环同样会出问题。因为
//随即后有可能变成与前面的已经判断过的数据重复
//解决的方法: 调用一个函数来判断是否有重复的数字,
//若返回值为1则表示有重复的数字,若返回值
//为0,则说明没有重复。可以进行赋值。
end;
//////////////////////
//下面是按从小到大的顺序排列
////////////////////
for i:=1 to 7 do
begin
for k:=i+1 to 7 do
if a[i]>a[k] then
begin
tmp:= a[i];
a[i] :=a[k];
a[k]:=tmp;
end;
end;
/////////////////////
for i:=1 to 7 do
begin
s:=inttostr(a[i]);
TEdit(FindComponent('Edit'+IntToStr(i))).Text:=s;
end;
/////////////////////
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -