急!!!!!关于delphi的问题

来源:百度知道 编辑:UC知道 时间:2024/05/17 08:33:11
10个100内的随机正数,求最大值。
我的程序:

var
a:array[1..10]of integer;
i:integer;

窗体
procedure TForm1.FormCreate(Sender: TObject);
begin
for i:=1 to 10 do
begin
randomize;
a[i]:=random(100);
lblnum.caption:=lblnum.caption+' '+inttostr(a[i]);
end;
自定义最大值函数:
function max(a:array of integer;n:integer):integer;
var
imax:integer;
begin
imax:=a[1];
for i:=2 to n do
if a[i]>imax then
imax:=a[i];
Result:=imax;
end;

最大值按钮
procedure TForm1.btnmaxClick(Sender: TObject);
begin
showmessage(inttostr(max(a,10)));
end;
end.

哪里出错?谢谢!!!

我把你的代码重新整合了下,是可以的...
procedure TForm1.Button1Click(Sender: TObject);
var
a : array[0..9] of integer;
i,imax : integer;
begin
Edit1.Clear;
for i := low(a) to high(a) do
begin
randomize;
a[i] := Random(100);
Edit1.Text := Edit1.Text + '; ' + IntToStr(a[i]);

end;
imax := a[0];
for i := low(a) to high(a) do
begin
if a[i] > imax then
imax := a[i];
end;
showmessage(inttostr(imax));
end;