list index out of bounds(1)

thumb0422 2010-04-15 09:57:45
list index out of bounds(1) 界面上就ADOQUERY,STRINGGRID,
z这个提示是哪儿的问题。
数据库表中有数据
...全文
1453 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
ywbcxq 2010-04-15
  • 打赏
  • 举报
回复
呵呵,贴的代码够长吧。
thumb0422 2010-04-15
  • 打赏
  • 举报
回复
我想很可能出现在STRINGGRID 的初始属性设置上,请教
thumb0422 2010-04-15
  • 打赏
  • 举报
回复
就是在F8的时候 执行到该单元的时候就出现list index out of bounds(1) 跳过该提示 后面的功能还能运行
thumb0422 2010-04-15
  • 打赏
  • 举报
回复

unit Input;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, ExtCtrls, Menus;

type
TFormInput = class(TForm)
Panel1: TPanel;
StringGrid1: TStringGrid;
btnInputSave: TButton;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Button2: TButton;
Label6: TLabel;
Edit5: TEdit;
Edit2: TEdit;
Edit3: TEdit;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
procedure Button2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure ComboBox2DropDown(Sender: TObject);
procedure StringGrid1DblClick(Sender: TObject);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure btnInputSaveClick(Sender: TObject);
procedure ComboBox1DropDown(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
//-------------设置选取的stringgrid单元成员的行,列值为public,以供其他窗体中调用-----------------

currentRow: integer;
currentCol:integer;

end;

var
FormInput: TFormInput;
currentRow: integer;
currentCol:integer;
implementation
uses InputReject,Manage,Login,Info,DtMoudle;
{$R *.dfm}

procedure TFormInput.Button2Click(Sender: TObject);
begin
InputRe.Visible:=True;

end;

procedure TFormInput.FormClose(Sender: TObject; var Action: TCloseAction);
var i:Integer;
begin
FormManage.Show;
//退出清空数据
//with StringGrid1 do
// for i:=1 to ColCount-1 do
//Cols[i].Clear;
end;

procedure TFormInput.FormCreate(Sender: TObject);
var i,j,num:Integer;
begin
//-------------设置stringgrid行,列名称---------------------
stringgrid1.Cols[0].Add('序号');
stringgrid1.ColWidths[0]:=32;
stringgrid1.Cols[1].Add('货号(双击)');
stringgrid1.ColWidths[1]:=60;
stringgrid1.Cols[2].Add('货名');
stringgrid1.ColWidths[2]:=100;
stringgrid1.Cols[3].Add('数量');
stringgrid1.ColWidths[3]:=60;
stringgrid1.Cols[4].Add('单位');
stringgrid1.ColWidths[4]:=60;
stringgrid1.Cols[5].Add('进价');
stringgrid1.ColWidths[5]:=60;
stringgrid1.Cols[6].Add('金额');
stringgrid1.ColWidths[6]:=60;
stringgrid1.Cols[7].Add('销售价');
stringgrid1.ColWidths[7]:=60;
//序号排序
for i:=1 to 20 do
begin
stringgrid1.Rows[i].Add(inttostr(i));
stringgrid1.RowHeights[i]:=20;
end;
end;

procedure TFormInput.ComboBox2DropDown(Sender: TObject);
var i:Integer;
begin
with DM.InputQry do
begin
Close;
SQL.Clear;
SQL.Text:='select 编号 from 供应商清单';
Open;
ComboBox2.Items.Clear;
while not Eof do
begin
ComboBox2.Items.Add(fieldbyname('编号').AsString);
Next;
end;
end;
with dm.InputQry do
begin
Close;
SQL.Clear;
SQL.Text:='select 名称 from 供应商清单 where 编号='''+combobox2.Text+'''' ;
Open;
Edit3.Text:=fieldbyname('名称').AsString;
Edit3.Enabled:=False;
end;

end;

procedure TFormInput.StringGrid1DblClick(Sender: TObject);
begin
if currentCol=1 then
begin
FormInfo.Visible:=True;
FormInfo.N2.Click;
FormInput.Enabled:=False;
end;
end;
//金额 统计
procedure TFormInput.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var price,number,sum:double;
j:integer;
begin
currentCol:=ACol;
currentRow:=ARow;
if (currentCol=4)and(stringgrid1.Cells[1,currentRow]<>'') then
begin
with DM.InputQry do
begin
Close;
SQL.Clear;
SQL.Add('select distinct 单位,进价,销售价 from 商品清单 where 编号='''+stringgrid1.Cells[1,currentRow]+'''');
Open;
stringgrid1.Cells[4,currentRow]:=DM.InputQry.FieldByName('单位').AsString;
stringgrid1.Cells[5,currentRow]:=DM.InputQry.FieldByName('进价').AsString;
stringgrid1.Cells[7,currentRow]:=DM.InputQry.FieldByName('销售价').AsString;
end;
end;



//--------------------当商品信息,数量,单价不为空时,才能进行计算------------------------
if (currentRow<>0)and(stringgrid1.Cells[1,currentRow]<>'')and(stringgrid1.Cells[3,currentRow]<>'')and(stringgrid1.Cells[5,currentRow]<>'') then
begin
//----------计算某条进货单明细的进货金额----------------------
number:=strtofloat(stringgrid1.Cells[3,currentRow]);
price:=strtofloat(stringgrid1.Cells[5,currentRow]);
stringgrid1.Cells[6,currentRow]:=floattostr(number*price);
end;
//----------------统计合计金额-----------------------
sum:=0;
for j:=1 to 20 do
if stringgrid1.Cells[6,j]<>'' then
sum:=sum+strtofloat(stringgrid1.Cells[6,j]);
edit5.Text:=floattostr(sum);
end;

procedure TFormInput.btnInputSaveClick(Sender: TObject);
var maxnum,maxnum2,temp,inputnum,inputnum2:string;
newnum,newnum2,i:integer;
begin
//--------------------为新插入的进货单和进货单明细数据计算编号-------------
with dm.InputQry do
begin
Close;
SQL.Clear;
SQL.Add('select max(编号) 最大编号 from 进货单');
Open;
maxnum:=DM.InputQry.fieldbyname('最大编号').AsString;
end;
//防止插入第一条记录时出错
if (maxnum='')or(maxnum=' ') then
temp:='00000'
else
temp:=copy(maxnum,1,5);

//新插入的进货单编号为插入前的最大编号+1
newnum:=strtoint(temp)+1;
//重新组合编码
if length(inttostr(newnum))=1 then
inputnum:='0000'+inttostr(newnum);
if length(inttostr(newnum))=2 then
inputnum:='000'+inttostr(newnum);
if length(inttostr(newnum))=3 then
inputnum:='00'+inttostr(newnum);
if length(inttostr(newnum))=4 then
inputnum:='0'+inttostr(newnum);
if length(inttostr(newnum))=5 then
inputnum:=inttostr(newnum);

//计算进货单明细最大编号以便插入新的进货单明细数据时编号不冲突
with DM.InputQry do
begin
Close;
SQL.Clear;
SQL.Add('select max(编号) 最大编号 from 进货单明细');
Open;
maxnum2:=fieldbyname('最大编号').AsString;
end;

//对读出的编号进行截取并将其转换为整数值,字段太长时可以不能用strtoint来转换
//防止插入第一条记录时出错
if (maxnum2='')or(maxnum2=' ') then
temp:='00000'
else
temp:=copy(maxnum2,1,5);
newnum2:=strtoint(temp);
if (combobox2.Text='')or(edit3.Text='') then
showmessage('供货商号不能为空,且进货单明细数据必须完整')
else
begin
//插入新的进货单数据
with DM.cmdInputCommand do
begin
CommandText:='insert into 进货单([编号],[供应商号],[供应商名],[进货日期],[制单人],[验收人]) values('''+inputnum+''','''+combobox2.Text+''','''+edit3.Text+''','''+edit1.Text+''','''+edit2.Text+''','''+combobox1.Text+''') ';
Execute;
end;
//根据进货单明细条目的数量,插入进货单明细数据
for i:=1 to 20 do
if stringgrid1.Cells[3,i]<>'' then
//重新组合编码
begin
newnum2:=newnum2+1;
if length(inttostr(newnum2))=1 then
inputnum2:='0000'+inttostr(newnum2);
if length(inttostr(newnum2))=2 then
inputnum2:='000'+inttostr(newnum2);
if length(inttostr(newnum2))=3 then
inputnum2:='00'+inttostr(newnum2);
if length(inttostr(newnum2))=4 then
inputnum2:='0'+inttostr(newnum2);
if length(inttostr(newnum2))=5 then
inputnum2:=inttostr(newnum2);
with DM.cmdInputCommand do
begin
CommandText:='insert into 进货单明细 ([编号],[进货单号],[货号],[货名],[数量],[单位],[进价],[金额],[销售价],[总额]) values ('''+inputnum2+''','''+inputnum+''','''+stringgrid1.Cells[1,i]+''','''+stringgrid1.Cells[2,i]+''','''+stringgrid1.Cells[3,i]+''','''+stringgrid1.Cells[4,i]+''','''+stringgrid1.Cells[5,i]+''','''+stringgrid1.Cells[6,i]+''','''+stringgrid1.Cells[7,i]+''','''+edit5.Text+''')';
Execute;
end;
end;
//通知用户,操作成功
showmessage('进货单及明细保存成功');

end;

end;

procedure TFormInput.ComboBox1DropDown(Sender: TObject);
begin
with DM.InputQry do
begin
Close;
SQL.Clear;
SQL.Text:='select 名称 from 员工清单';
Open;
ComboBox1.Items.Clear;
while not Eof do
begin
ComboBox1.Items.Add(fieldbyname('名称').AsString);
Next;
end;
end;
end;

procedure TFormInput.FormShow(Sender: TObject);
begin
Edit1.Text:=DateToStr(Date);
Edit2.Text:=FormLogin.Edit2.Text;
currentCol:=1;
currentRow:=1;
end;

procedure TFormInput.FormDestroy(Sender: TObject);
begin
Close;
end;

end.


duduxia 2010-04-15
  • 打赏
  • 举报
回复
贴代码啦!!!!!!!!!!!!
thumb0422 2010-04-15
  • 打赏
  • 举报
回复
但是根本就没有运行到ADOQUERY那里,而stringgird 也不像DBGRID 有DATASOURCE属性啊
hongss 2010-04-15
  • 打赏
  • 举报
回复
相关代码贴出来看看
kfcoffe 2010-04-15
  • 打赏
  • 举报
回复
ADOQUERY,STRINGGRID 对这2个地Titem操作溢出

也就是说ADOQUERY或者STRINGGRID当前里面没有内容,但是你又试着去访问ADOQUERY的第一条记录这个时候就会报错~~~~~~
thumb0422 2010-04-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 taxi 的回复:]
一句代码都没有写?一般这种情况是访问了对象的数组属性导致的,如TList.Items.
[/Quote]
有代码。
断点 在formcreate 就出现该提示
taxi 2010-04-15
  • 打赏
  • 举报
回复
一句代码都没有写?一般这种情况是访问了对象的数组属性导致的,如TList.Items.
thumb0422 2010-04-15
  • 打赏
  • 举报
回复
搞定了。还是formshow 与formcreate之间的问题。
thumb0422 2010-04-15
  • 打赏
  • 举报
回复

procedure TFormInfo.FormCreate(Sender: TObject);
begin
DBGrid1.Columns[1].Width:=80;
DBGrid1.Columns[2].Width:=100;//跳到这句弹出 list index out of bound(1)
DBGrid1.Columns[3].Width:=80;
DBGrid1.Columns[4].Width:=80;
DBGrid1.Columns[5].Width:=80;
DBGrid1.Columns[6].Width:=80;
DBGrid1.Columns[7].Width:=80;
DBGrid1.Columns[8].Width:=100;
DBGrid1.Columns[9].Width:=100;

先F8进去 然后F7 在执行到这里就弹出,这算什么
ffwin 2010-04-15
  • 打赏
  • 举报
回复
你跟踪的时候,在按F8出现错误提示的行上,按F7进去,然后再F8,试试,一句一句执行,就知道哪行出错了,一看就明白原因了
ffwin 2010-04-15
  • 打赏
  • 举报
回复
你跟踪的时候,在按F8出现错误提示的行上,按F7进去,然后再F8,试试,一句一句执行,就知道哪行出错了,一看就明白原因了
thumb0422 2010-04-15
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 ffwin 的回复:]
检查一下stringgrid1的行数是多少?是否很小?
[/Quote]我注意到这个了 循环是1-20,我设置的行数是21。 改大 改小 都是一样的提示
ffwin 2010-04-15
  • 打赏
  • 举报
回复
检查一下stringgrid1的行数是多少?是否很小?

829

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧