delphi出现EAccessViolation 的错误
varAdmin:TAdmin;number:integer;implementationusesFormManage;{$R*.dfm}procedureTAdmin....
var
Admin: TAdmin;
number:integer;
implementation
uses FormManage;
{$R *.dfm}
procedure TAdmin.FormCreate(Sender: TObject);
begin
Edit1.Clear;
ComboBox1.ItemIndex:=0;
DBGrid1.Columns.Items[2].Font.Color:=clRed;
DBGrid1.Columns.Items[3].Font.Color:=clRed;
for number:=0 to 6 do
begin
DBGrid1.Fields[number].DisplayWidth:=10;
DBGrid1.Columns.Items[number].Alignment:=taLeftJustify;
end
end;
procedure TAdmin.Button1Click(Sender: TObject);
begin
if ComboBox1.ItemIndex<> 5 then
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 药品信息 where '+ComboBox1.Items[ComboBox1.ItemIndex]+' = '''+edit1.Text+'''');
adoquery1.Open;
end
else
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 药品信息');
adoquery1.Open;
end
end;
procedure TAdmin.Button2Click(Sender: TObject);
var SellSum,StockSum:double;
begin
//DBText1.DataField:='Summary';
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select sum(销售金额) as summation from 销售情况');
adoquery2.Open;
SellSum:=AdoQuery2.FieldValues['summation'];
// ShowMessage(FloatToStr(SellSum));
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select sum(药品信息.进货单价*销售情况.销售数量) as StockSum from (销售情况 left outer join 药品信息 on 销售情况.药品代码=药品信息.药品代码);');
adoquery2.Open;
StockSum:=AdoQuery2.fieldValues['StockSum'];
// MessageBox('This should be on top.','Look', mb_OK)
//windows.messagebox(0,'标题','警告错误',MB_ICONSTOP);
// if messagedlg('确定要退出吗?',mtwarnint,[mbyes,mbno],0)=mryes then close;
ShowMessage('你当前的销售总金额为'+FloatToStr(SellSum)+'!当前您盈利为:'+FloatToStr(SellSum-StockSum)+'!');
end;
procedure TAdmin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
manage.Show;
end;
procedure TAdmin.ComboBox1Change(Sender: TObject);
begin
if ComboBox1.ItemIndex=5 then
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 药品信息');
adoquery1.Open;
end
end;
procedure TAdmin.DBGrid1ColExit(Sender: TObject);
begin
//AdoQuery1.Post;
end;
end.
运行时提示出现 Project ypjxc.exe raised exception class EAccessViolation with message 'Access violation at address 0047FB80 in module 'ypjxc.exe'. Read of address 00000054'. Process stopped.Use Step or Run to continue.
请问哪里出问题了?
是一运行就出现错误 错误指在这一行 DBGrid1.Fields[number].DisplayWidth:=10; 可以给我留个QQ吗?谢谢 展开
Admin: TAdmin;
number:integer;
implementation
uses FormManage;
{$R *.dfm}
procedure TAdmin.FormCreate(Sender: TObject);
begin
Edit1.Clear;
ComboBox1.ItemIndex:=0;
DBGrid1.Columns.Items[2].Font.Color:=clRed;
DBGrid1.Columns.Items[3].Font.Color:=clRed;
for number:=0 to 6 do
begin
DBGrid1.Fields[number].DisplayWidth:=10;
DBGrid1.Columns.Items[number].Alignment:=taLeftJustify;
end
end;
procedure TAdmin.Button1Click(Sender: TObject);
begin
if ComboBox1.ItemIndex<> 5 then
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 药品信息 where '+ComboBox1.Items[ComboBox1.ItemIndex]+' = '''+edit1.Text+'''');
adoquery1.Open;
end
else
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 药品信息');
adoquery1.Open;
end
end;
procedure TAdmin.Button2Click(Sender: TObject);
var SellSum,StockSum:double;
begin
//DBText1.DataField:='Summary';
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select sum(销售金额) as summation from 销售情况');
adoquery2.Open;
SellSum:=AdoQuery2.FieldValues['summation'];
// ShowMessage(FloatToStr(SellSum));
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select sum(药品信息.进货单价*销售情况.销售数量) as StockSum from (销售情况 left outer join 药品信息 on 销售情况.药品代码=药品信息.药品代码);');
adoquery2.Open;
StockSum:=AdoQuery2.fieldValues['StockSum'];
// MessageBox('This should be on top.','Look', mb_OK)
//windows.messagebox(0,'标题','警告错误',MB_ICONSTOP);
// if messagedlg('确定要退出吗?',mtwarnint,[mbyes,mbno],0)=mryes then close;
ShowMessage('你当前的销售总金额为'+FloatToStr(SellSum)+'!当前您盈利为:'+FloatToStr(SellSum-StockSum)+'!');
end;
procedure TAdmin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
manage.Show;
end;
procedure TAdmin.ComboBox1Change(Sender: TObject);
begin
if ComboBox1.ItemIndex=5 then
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 药品信息');
adoquery1.Open;
end
end;
procedure TAdmin.DBGrid1ColExit(Sender: TObject);
begin
//AdoQuery1.Post;
end;
end.
运行时提示出现 Project ypjxc.exe raised exception class EAccessViolation with message 'Access violation at address 0047FB80 in module 'ypjxc.exe'. Read of address 00000054'. Process stopped.Use Step or Run to continue.
请问哪里出问题了?
是一运行就出现错误 错误指在这一行 DBGrid1.Fields[number].DisplayWidth:=10; 可以给我留个QQ吗?谢谢 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询