unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(Edit1.handle, GWL_STYLE, GetWindowLong(Edit1.Handle,GWL_STYLE)+ES_CENTER);
Edit1.Refresh;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
RunNum:Array[1..10] of Integer;
i:Integer;
Max,Maxi:Integer; //Max为最大数字,Maxi为最大数字下标
begin
Randomize;
Edit1.text:= '';
Edit2.Text:= '';
For i:=1 to 10 do
begin
RunNum[i]:=10 + Random(90);
Edit1.Text:=Edit1.Text + IntToStr(RunNum[i]) + ',' ;
end;
Edit1.Text:=Copy(Edit1.Text,1,Length(Edit1.Text)-1);
Max:=RunNum[1]; //假设第一个下标的值为最大值
Maxi:=1;
For i:=2 to 10 do
begin
If Max < RunNum[i] then
begin
Max:=RunNum[i];
Maxi:=i;
end
end;
Edit2.Text:=IntToStr(Max);
Edit3.text:=IntToStr(Maxi);
end;
end.
最后修改:2022 年 12 月 05 日
© 允许规范转载