小白求解。。。使用动态数组的时候会出现内存报错,求各位大神指教。
学习小甲鱼老师的制作表格,于是自己想用动态数组弄一遍,结果出现了令我这种程序小白干瞪眼的情况,望各位大神指教下。:cryunit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Grids;
type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Table1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
InputStr: String;
Tab: Array of Array of String;
implementation
var
n: Integer = 1;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
InputStr:= InputBox('请输入','请输入需要录入的人数:','');
Button2.Enabled:=False;
SetLength(Tab,4,StrToInt(InputStr)+1);
Table1.RowCount:= StrToInt(InputStr)+1;
Table1.Cells:='姓名';
Table1.Cells:='语文';
Table1.Cells:='数学';
Table1.Cells:='英语';
Table1.Visible:= False;
Form1.AutoSize:= True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
If(n<StrToInt(InputStr)) then
begin
Tab:= Edit1.Text;
Tab:= Edit2.Text;
Tab:= Edit3.Text;
Tab:= Edit4.Text;
end
else
begin
Tab:= Edit1.Text;
Tab:= Edit2.Text;
Tab:= Edit3.Text;
Tab:= Edit4.Text;
Button1.Enabled:= False;
Button2.Enabled:= True;
end;
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
Edit4.Clear;
Button1.Caption:=IntToStr(StrToInt(InputStr)-n)+'/'+InputStr;
n := n + 1;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i,j: Integer;
begin
For j:=1 to StrToInt(InputStr) do
begin
For i:=0 to 4 do
Table1.Cells:=Tab;
end;
Table1.Visible:= True;
end;
end.
setlength(Tap,StrToInt(InputStr)+1) 蚂蚁_Data 发表于 2015-1-12 12:09
setlength(Tap,StrToInt(InputStr)+1)
{:5_92:}谢谢啊,是最后循环那里次数粗心弄错了。
页:
[1]