list index out of bounds解决方案

list index out of bounds
unit Unit6;

interface

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

type
  TForm6 = class(TForm)
  ToolBar1: TToolBar;
  ToolButton1: TToolButton;
  ToolButton2: TToolButton;
  ToolButton3: TToolButton;
  ToolButton4: TToolButton;
  ToolButton5: TToolButton;
  ToolButton6: TToolButton;
  ADOQuery1: TADOQuery;
  ADOTable1: TADOTable;
  DBGrid1: TDBGrid;
  DataSource1: TDataSource;
  PageControl1: TPageControl;
  GroupBox1: TGroupBox;
  Label1: TLabel;
  Label2: TLabel;
  Label3: TLabel;
  Label4: TLabel;
  Label5: TLabel;
  Label6: TLabel;
  Edit1: TEdit;
  Edit2: TEdit;
  Edit3: TEdit;
  Edit4: TEdit;
  Edit5: TEdit;
  Edit6: TEdit;
  PopupMenu1: TPopupMenu;
  procedure FormShow(Sender: TObject);
  procedure ToolButton1Click(Sender: TObject);
  procedure ToolButton2Click(Sender: TObject);
  procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  procedure ToolButton3Click(Sender: TObject);
  procedure ToolBar1Click(Sender: TObject);
  procedure ADOTable1AfterScroll(DataSet: TDataSet);
  procedure ToolButton5Click(Sender: TObject);
  procedure ToolButton6Click(Sender: TObject);
  private
  { Private declarations }
  pmark:integer;
  function ptest():string;

  public
  { Public declarations }
  end;

var
  Form6: TForm6;

implementation

uses Unit3;

{$R *.dfm}

procedure TForm6.ADOTable1AfterScroll(DataSet: TDataSet);
begin
edit1.Text:=adotable1.FieldByName('roomid').AsString;
edit2.Text:=adotable1.FieldByName('roomtype').AsString;
edit3.Text:=adotable1.FieldByName('tvor').AsString;
edit4.Text:=adotable1.FieldByName('airconditionaryor').AsString;
edit5.Text:=adotable1.FieldByName('netor').AsString;
edit6.Text:=adotable1.FieldByName('price').AsString;

edit1.ReadOnly:=true;
edit2.ReadOnly:=true;
edit3.ReadOnly:=true;
edit4.ReadOnly:=true;
edit5.ReadOnly:=true;
edit6.ReadOnly:=true;
 pmark:=2;
end;

procedure TForm6.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
  var
  x,x1:integer;
  tc:tcomponent;
  begin
  if not (ActiveControl is TDBGrid) then
  begin
  if (key=13)or(key=vk_down) then
  begin
  perform (WM_NEXTDLGCTL,0,0);
  end;
  if key=VK_UP then perform(WM_NEXTDLGCTL,1,0);
  end;
end;

procedure TForm6.FormShow(Sender: TObject);
var
  i:integer;
begin
 adoquery1.Connection:=datamodule3.ADOConnection1;
 adotable1.connection:=datamodule3.ADOConnection1;

 adotable1.Close;
 adotable1.TableName:='room';
 adotable1.Open;

 with dbgrid1 do
 begin
  columns.clear;

for i := 0 to 5 do columns.Add;
  columns[0].Title.caption:='房间号';
  columns[1].Title.caption:='房间类型';
  columns[2].Title.caption:='是否有电视';
  columns[3].Title.caption:='是否有空调';
  columns[4].Title.caption:='是否有宽带';
  columns[5].Title.caption:='价格';

  columns[0].fieldname:='roomid';
  columns[1].fieldname:='roomtype';