请老兄帮助解决一个问题
delphi中的TStringGrig问题 用于显示计算数据
代码是:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, DBGrids, DB, DBTables, DBCtrls;
type
TForm1 = class(TForm)
Table1: TTable;
DCGrid: TStringGrid;
DBLookupComboBox1: TDBLookupComboBox;
DBLookupComboBox2: TDBLookupComboBox;
BitBtn1: TBitBtn;
Label1: TLabel;
Label2: TLabel;
DataSource1: TDataSource;
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
rr1:array[1..70] of real;rr2:array[1..70] of real;rr3:array[1..70] of real;rr4:array[1..70] of real;rr5:array[1..70] of real;
rr6:array[1..70] of real;rr7:array[1..70] of real;rr8:array[1..70] of real;rr9:array[1..70] of real;rr10:array[1..70] of real;rr11:array[1..70] of real;rr12:array[1..70] of real;
s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13:string;
sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9,sum10,sum11,sum12:real;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
var a,j:integer;
begin
begin
DCGrid.Cells[0,0]:='编号';
DCGrid.Cells[1,0]:='年代';
DCGrid.Cells[2,0]:='一月';
DCGrid.Cells[3,0]:='二月';
DCGrid.Cells[4,0]:='三月';
DCGrid.Cells[5,0]:='四月';
DCGrid.Cells[6,0]:='五月';
DCGrid.Cells[7,0]:='六月';
DCGrid.Cells[8,0]:='七月';
DCGrid.Cells[9,0]:='八月';
DCGrid.Cells[10,0]:='九月';
DCGrid.Cells[11,0]:='十月';
DCGrid.Cells[12,0]:='十一月';
DCGrid.Cells[13,0]:='十二月';
for a:=1 to DCGrid.RowCount-1do
begin
DCGrid.Cells[0,a]:=intToStr(a);
end;
end;
begin
sum1:=0.00;sum2:=0.00;sum3:=0.00;sum4:=0.00;sum5:=0.00;sum6:=0.00;
sum7:=0.00;sum8:=0.00;sum9:=0.00;sum10:=0.00;sum11:=0.00;sum12:=0.00;
table1.disablecontrols;//禁止数据表功能
table1.first;
for j:=1 to table1.RecordCount-1do
begin
rr1[j]:=StrToFloat(table1.fieldbyname('一月').asstring);
rr2[j]:=StrToFloat(table1.fieldbyname('二月').asstring);
rr3[j]:=StrToFloat(table1.fieldbyname('三月').asstring);
rr4[j]:=StrToFloat(table1.fieldbyname('四月').asstring);
rr5[j]:=StrToFloat(table1.fieldbyname('五月').asstring);
rr6[j]:=StrToFloat(table1.fieldbyname('六月').asstring);
rr7[j]:=StrToFloat(table1.fieldbyname('七月').asstring);
rr8[j]:=StrToFloat(table1.fieldbyname('八月').asstring);
rr9[j]:=StrToFloat(table1.fieldbyname('九月').asstring);
rr10[j]:=StrToFloat(table1.fieldbyname('十月').asstring);
rr11[j]:=StrToFloat(table1.fieldbyname('十一月').asstring);
rr12[j]:=StrToFloat(table1.fieldbyname('十二月').asstring);
sum1:=sum1+rr1[j];
sum2:=sum1+rr2[j];
sum3:=sum1+rr3[j];
sum4:=sum1+rr4[j];
sum5:=sum1+rr5[j];
sum6:=sum1+rr6[j];
sum7:=sum1+rr7[j];
sum8:=sum1+rr8[j];
sum9:=sum1+rr9[j];
sum10:=sum1+rr10[j];
sum11:=sum1+rr11[j];
sum12:=sum1+rr12[j];
table1.Next;
end;
table1.close;
end;
begin
table1.close;
table1.Open;
table1.first;
for j:=1 to table1.RecordCount-1do
begin
DCGrid.cells[1,j]:=table1.fieldbyname('年代').asstring;
str((StrToFloat(table1.fieldbyname('一月').asstring)-sum1)/sum1:6:1,s2);
str((StrToFloat(table1.fieldbyname('二月').asstring)-sum2)/sum2:6:1,s3);
str((StrToFloat(table1.fieldbyname('三月').asstring)-sum3)/sum3:6:1,s4);
str((StrToFloat(table1.fieldbyname('四月').asstring)-sum4)/sum4:6:1,s5);
str((StrToFloat(table1.fieldbyname('五月').asstring)-sum5)/sum5:6:1,s6);
str((StrToFloat(table1.fieldbyname('六月').asstring)-sum6)/sum6:6:1,s7);
str((StrToFloat(table1.fieldbyname('七月').asstring)-sum7)/sum7:6:1,s8);
str((StrToFloat(table1.fieldbyname('八月').asstring)-sum8)/sum8:6:1,s9);
str((StrToFloat(table1.fieldbyname('九月').asstring)-sum9)/sum9:6:1,s10);
str((StrToFloat(table1.fieldbyname('十月').asstring)-sum10)/sum10:6:1,s11);
str((StrToFloat(table1.fieldbyname('十一月').asstring)-sum11)/sum11:6:1,s12);
str((StrToFloat(table1.fieldbyname('十二月').asstring)-sum12)/sum12:6:1,s13);
table1.EnableControls;//取消禁止
DCGrid.cells[2,j]:=s2;
DCGrid.cells[3,j]:=s3;
DCGrid.cells[4,j]:=s4;
DCGrid.cells[5,j]:=s5;
DCGrid.Cells[6,j]:=s6;
DCGrid.Cells[7,j]:=s7;
DCGrid.Cells[8,j]:=s8;
DCGrid.Cells[9,j]:=s9;
DCGrid.Cells[10,j]:=s10;
DCGrid.Cells[11,j]:=s11;
DCGrid.Cells[12,j]:=s12;
DCGrid.Cells[13,j]:=s13;
table1.Next;
end;
table1.Close;
table1.open;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
close;
end;
end.
编译运行,出错,请你给找出问题所在。谢谢!