About List Index out of bounds (0)

Source: Internet
Author: User
About List Index out of bounds (0) Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiDB/html/delphi_20061223203333140.html
After you press the OK button to run the input data, the pop-up dialog box says List Index out of bounds (0). Why is this error. Code As follows:
Unit borrow;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, DB, dbtables, mask, dbctrls, stdctrls;

Type
Tborrowform = Class (tform)
Groupbox1: tgroupbox;
Groupbox2: tgroupbox;
Groupbox3: tgroupbox;
Label1: tlabel;
Edit1: tedit;
Label2: tlabel;
Edit2: tedit;
Button1: tbutton;
Dbedit1: tdbedit;
Query1: tquery;
Query2: tquery;
Query3: tquery;
Query4: tquery;
Performance1: tdatasource;
Performance2: tdatasource;
Required int32: tdatasource;
Label3: tlabel;
Label4: tlabel;
Dbedit2: tdbedit;
Label5: tlabel;
Dbedit3: tdbedit;
Label6: tlabel;
Dbedit4: tdbedit;
Dbedit5: tdbedit;
Label7: tlabel;
Label8: tlabel;
Label9: tlabel;
Label10: tlabel;
Dbedit6: tdbedit;
Dbedit7: tdbedit;
Dbedit8: tdbedit;
Button2: tbutton;
Button3: tbutton;
Button4: tbutton;
Button5: tbutton;
Procedure button1click (Sender: tobject );
Procedure button2click (Sender: tobject );
Procedure button3click (Sender: tobject );
Procedure button4click (Sender: tobject );
Procedure button5click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Borrowform: tborrowform;

Implementation

Uses query, return;

{$ R *. DFM}

Procedure tborrowform. button1click (Sender: tobject );
Begin
If edit1.text = ''then
Showmessage ('enter the Book Number and reader number! ')
Else
If edit2.text = ''then
Else
Begin
Query1.params [0]. asstring: = edit1.text;
Query1.execsql;
Query1.active: = true;
Query2.params [0]. asstring: = edit2.text;
Query2.execsql;
Query2.active: = true;
Query3.params [0]. asstring: = edit2.text;
Query3.execsql;
Query3.active: = true;
End;
End;

Procedure tborrowform. button2click (Sender: tobject );
Begin
If dbedit4.text = ''then
Showmessage ('the book has been lent out. Please select another one! ')
Else
Begin
Query4. SQL. Clear;
Query4. SQL. Add ('insert into borrow values (edit1.text, edit2.text, sysdate )');
Query4.execsql;
Query4. SQL. Clear;
Query4. SQL. Add ('Update book set lending No: = true where Book Number = edit1.text ');
Query4.execsql;
Query4.close;
End;
End;

Procedure tborrowform. button3click (Sender: tobject );
Begin
Queryform. show;
End;

Procedure tborrowform. button4click (Sender: tobject );
Begin
Returnform. show;
End;

Procedure tborrowform. button5click (Sender: tobject );
Begin
Borrowform. close;
End;

End.

Day, your name is too much...
I don't know which button is yours.
This error is a common message indicating that the list is out of bounds. An empty list value is referenced.
Look for the reason.

I am a cainiao. What is "list out of bounds?

Thank you for helping me solve the problem.

F8 breakpoint debugging

Query1.params [0]. asstring: = edit1.text;
Query2.params [0]. asstring: = edit2.text;
Query3.params [0]. asstring: = edit2.text;
---------------------------------------

The problem lies in your query1 ~ In query3. Are you sure you have parameters in each query SQL statement? It is certain that at least one parameter is not included. Check. After the parameter is added, everything will be greatly OK.

I am still a little surprised by Feng.

Lao Feng is right! Check whether SQL has any parameters.
In addition, your code has an error:
query4. SQL. add ('insert into borrow values (edit1.text, edit2.text, sysdate) ');
query4.execsql;
query4. SQL. clear;
query4. SQL. add ('Update book set lending No: = true where Book Number = edit1.text');
query4.execsql;
query4.close;
the value of Edit cannot be referenced in query4 as follows, for example, query4. SQL. add ('insert into borrow values (''' + edit1.text + ''', '+ ''' + edit2.text + ''', sysdate )');

There are too many errors in the code, as you mentioned above.
In addition, execsql and active: = true should not be used in disorder or mixed.

I am in query1 ~ Query3 has parameters:
Query1:
Select * from book where Book Number = '+ ''' + edit1.text + '''
Query2:
Select * From Reader where number = '+ ''' + edit1.text + '''
Query3:
Select STR (count (*) + 'bene' from borrow where reader id = '+ ''' + edit1.text + '''
Excuse me, are these parameters correct?
My above gaveProgramIs used to realize the function of borrowing books in the library management system.

Error query1 ~ The query3 parameter should be:
Query1:
Select * from book where Book Number = '+ ''' + edit1.text + '''
Query2:
Select * From Reader where number = '+ ''' + edit2.text + '''
Query3:
Select STR (count (*) + 'bene' from borrow where reader id = '+ ''' + edit2.text + '''
Are these parameters correct?

You have no parameters.

It's no wonder that the border is crossed. No parameter.
There are also SQL statements without: =.
Query4. SQL. Add ('Update book set lending No: = true where Book Number = edit1.text ');

How can I set parameters? Experts.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.