|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
学习小甲鱼老师的制作表格,于是自己想用动态数组弄一遍,结果出现了令我这种程序小白干瞪眼的情况,望各位大神指教下。:cry
unit 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[0,0]:='姓名';
Table1.Cells[1,0]:='语文';
Table1.Cells[2,0]:='数学';
Table1.Cells[3,0]:='英语';
Table1.Visible:= False;
Form1.AutoSize:= True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
If(n<StrToInt(InputStr)) then
begin
Tab[0][n]:= Edit1.Text;
Tab[1][n]:= Edit2.Text;
Tab[2][n]:= Edit3.Text;
Tab[3][n]:= Edit4.Text;
end
else
begin
Tab[0][n]:= Edit1.Text;
Tab[1][n]:= Edit2.Text;
Tab[2][n]:= Edit3.Text;
Tab[3][n]:= 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[i,j]:=Tab[i][j];
end;
Table1.Visible:= True;
end;
end.
|
-
报错显示
|