|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
二维数组的实践结果,delphi中比较容易搞混数组的下标是行还是列。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
strngrdtable1: TStringGrid;
btn1: TButton;
procedure FormCreate(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
strngrdtable1.Cells[0,1]:= '小明';
strngrdtable1.Cells[0,2]:= '小红';
strngrdtable1.Cells[1,0]:= '语文';
strngrdtable1.Cells[2,0]:= '数学';
strngrdtable1.Cells[3,0]:= '英语';
strngrdtable1.Cells[4,0]:= '总成绩';
end;
procedure TForm1.btn1Click(Sender: TObject);
var
i,j: Integer;
cjb: array[1..4] of array [1..2] of Integer;
begin
for i:= 1 to 2 do
begin
cjb[4,i]:= 0;
begin
for j:= 1 to 3 do
begin
cjb[j][i]:= StrToInt(strngrdtable1.Cells[j,i]);
cjb[4][i]:= cjb[4][i] + cjb[j][i];
end;
end;
end;
strngrdtable1.Cells[4,1]:= IntToStr(cjb[4][1]);
strngrdtable1.Cells[4,2]:= IntToStr(cjb[4][2]);
end;
end.
简易成绩表
|
|