效果图
输入框不可修改
设置edit控件的readonly属性为true。
生成随机数
Randomize 函数通过获取系统时钟的当前时间(或其他系统特定的随机源)来自动设置随机数生成器的种子。这样,每次程序运行时,由于系统时间的不同,都会得到不同的随机数序列。
Randomize;
edt1.Text:='';
for i:=1 to 10 do
beginnum[i] := 10 + Random(90);edt1.Text:=edt1.Text+inttostr(num[i])+',';
end;
//去除末尾的逗号
edt1.Text:=copy(edt1.Text,1,length(edt1.Text)-1);
对随机数列排序
遍历数组来找到最大值。
max:=num[1];
for i:=2 to 10 do
beginif (max<num[i]) thenbeginmax:=num[i];max_i:=i;end;
end;
mp4转gif
网站在这,上一篇文章使用过。
完整代码
unit searchrandom;interfaceusesSysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,Dialogs, Forms,Form, Formprpt, StdCtrls;typeTForm1 = class(MForm)edt1: TEdit;btn1: TButton;edt2: TEdit;edt3: TEdit;lbl1: TLabel;lbl2: TLabel;procedure btn1Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementation{$R *.DFM}procedure TForm1.btn1Click(Sender: TObject);
varnum:array[1..10] of Integer;i:Integer; //for循环使用max:Integer;//最大值max_i:Integer;//最大值的下标beginRandomize;edt1.Text:='';for i:=1 to 10 dobeginnum[i] := 10 + Random(90);edt1.Text:=edt1.Text+inttostr(num[i])+',';end;//去除末尾的逗号edt1.Text:=copy(edt1.Text,1,length(edt1.Text)-1);//找最大值及其下标max:=num[1];for i:=2 to 10 dobeginif (max<num[i]) thenbeginmax:=num[i];max_i:=i;end;end;edt2.Text:=inttostr(max);edt3.Text:=inttostr(max_i);
end;end.