delphi 随机字符串

来源:百度知道 编辑:UC知道 时间:2024/06/16 23:22:27
我想先定义一个数组,里面包含六个字符串,分别是:我,你,他,我们,他们,你们。用一个timer控件随机把值付给label1,该怎么写?

procedure TForm1.Timer1Timer(Sender: TObject);
var
Test: array[1..6] of string;
begin
Test[1] := '我';
Test[2] := '你';
Test[3] := '他';
Test[4] := '我们';
Test[5] := '你们';
Test[6] := '他们';
Randomize; //随机数初始化
Label1.Caption := Test[Random(6)];
end;

const
ArrOur:array[0..5] of string=('我','你','他','我们','他们','你们');
procedure TForm1.tmr1Timer(Sender: TObject);
begin
Randomize;
label1.Caption:=arrour[Random(5)];
end;