list index out of bounds(1)

oowin 2008-03-23 10:15:58
unit Formcount;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Grids, DBGrids, ComCtrls, Buttons, ToolWin,
DB, ADODB;

type
TForm11 = class(TForm)
Panel1: TPanel;
ToolBar1: TToolBar;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
ToolButton1: TToolButton;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
BitBtn7: TBitBtn;
ToolButton2: TToolButton;
BitBtn8: TBitBtn;
BitBtn9: TBitBtn;
ToolButton3: TToolButton;
BitBtn10: TBitBtn;
DBGrid2: TDBGrid;
Bevel4: TBevel;
Label1: TLabel;
Label2: TLabel;
ComboBox1: TComboBox;
Button2: TButton;
Label3: TLabel;
Edit1: TEdit;
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
DBGrid1: TDBGrid;
ComboBox2: TComboBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ComboBox2Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form11: TForm11;

implementation
uses FormKaoQin;
{$R *.dfm}

procedure TForm11.FormCreate(Sender: TObject);
begin
try
if (Screen.Width=800) and (Screen.Height=600) then
begin
Form10.Left:=0;
Form10.Width:=649;
Form10.Top:=0;
Form10.Height:=638;
end;
if (Screen.Width=1024) and ( Screen.Height=768) then
begin
Form10.Width:=649;
Form10.Height:=638;
Form10.Position:=poDesktopCenter;
end;
except
Application.MessageBox('请正确选择屏幕分辨率:1024X768 或 800X600 !','提示!',0+64);
exit;
end;
end;

procedure TForm11.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Form10.Visible:=true;
Form11.Hide;
end;

procedure TForm11.ComboBox2Change(Sender: TObject);
var
temp:string;
sqlstr:string;
begin
temp:=trim(combobox2.text) ;
sqlstr := 'select * from ' + temp ;
ADOQuery1.active := false;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(sqlstr);
ADOQuery1.active :=true;
dbgrid1.Columns[0].Width:=80;
dbgrid1.Columns[1].Width:=60;
dbgrid1.Columns[2].Width:=180;
dbgrid1.Columns[3].Width:=50;

end;

end.




----------------------------
运行后出现问题是:list index out of bounds(1).这个究竟是什么原因?怎么解决呢
...全文
83 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ydlchina 2008-03-23
  • 打赏
  • 举报
回复
dbgrid1.Columns[0].Width:=80;
dbgrid1.Columns[1].Width:=60;
dbgrid1.Columns[2].Width:=180;
dbgrid1.Columns[3].Width:=50; //看你的dbgrid默认是否有这么多列,没有就增加上(4列)
forbearORfolie 2008-03-23
  • 打赏
  • 举报
回复
looklook
qkhhxkj102 2008-03-23
  • 打赏
  • 举报
回复
呵呵
radarhp 2008-03-23
  • 打赏
  • 举报
回复
楼上的都说完了……还说什么呢?总而言之再言而总之,数组越界了,调试检查,呵呵
byteh 2008-03-23
  • 打赏
  • 举报
回复
你的dbgrid是和数据库绑定的,列数是由ADOQuery1.SQL查询出来列数决定的,看看你的temp表里面是否有4列
huayuxing 2008-03-23
  • 打赏
  • 举报
回复
list index out of bounds(1).首先要弄清这是数组越界的问题,然后再查哪里用到了数组

828

社区成员

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

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