为什么给动态数组赋值的时候出错
附件是实例代码,每次运行到给动态数组赋值的语句处就出错了,小弟初学,应该是犯了什么低级的错误,希望大侠指点一下,谢谢了,
以下是复制的代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
lbl1: TLabel;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
shuzu: Array of Integer;//申请一个动态数组
n: Integer =0 ;
i: Integer;
tmp: String;
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
tmp:='123'; //字符串变量赋值
inc(n); //变量n加1
shuzu:= StrToInt(tmp); //运行到到这里就出错了
for i:=1 to n do
begin
lbl1.Caption:= lbl1.Caption + IntToStr(shuzu);
end;
end;
end.
人气不旺啊,那位大侠看到了顺便指点一下啊 问题解决了,少了一个设置数组元素的语句
SetLength(shuzu,6);
页:
[1]