I.T. Discussion Community!
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

June Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyPascal and Delphi Coding BoardDelphi News / Other Topic   Print This     

List index

List index in Delphi News / Other topic (part of our Pascal and Delphi Coding group).

Quick Search: List index  
rt
Castel, -- UK
Meanwhile, back in the land of simple SQL I get this error message when running a dynamic params type query and cannot seem to find it's meaning -

"List index out of bounds (0)"

I have a feeling this is an easy one Big Grin! , but..

Thats enough of that. Ed.

 Posted 18 years ago (Thread Starter)
Comment Quote
About rt -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About rt

I do like my jazz and blues!


Post ID #8588, 8 replies
Thread Started 12/10/2002 4:47:00 AM
View Counter=2685
Last Reply Posted 12/12/2002 6:38:00 AM)
Location=Castel, -- UK 
Joined=20 years ago   MB Posts=687   KB Comments=1  
rt
Castel, -- UK
In in order not to cockup the actual application I now test my bits of SQL and reports as very basic programs connected to the correct tables - the frills can come later!

So this program comprises a form with grid, datasource, SQL, editbox and a button and the following code -

Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add ('SELECT *');
Query1.SQL.Add ('FROM Client.db');
Query1.SQL.Add('FROM ":Contract:Client.db"'); // the Alias
Query1.Params[0].AsString := edit1.Text; // not working
// Query1.SQL.Add('WHERE Months = ''' + edit1.Text + ''''); //this works
Query1.Open;

The line I have commented as working does.
But the line above brings up the error message as posted if the Value section of the Params section is left blank. But, if say, the params value "April" is entered then it works directly from the button without the editbox.

I hope you can make sense of this!
rt

Thats enough of that. Ed.

 Posted 18 years ago (Thread Starter)
Comment Quote
About rt -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About rt

I do like my jazz and blues!


Post ID #8599 (Level 1.1)  Reply to 8588
Thread Started 12/11/2002 2:12:00 AM
View Counter=2
Location=Castel, -- UK 
Joined=20 years ago   MB Posts=687   KB Comments=1  
rt
Castel, -- UK
Larry I think you have won the prize in getting this to work Big Grin!

And thanks to Rick as well I shall give your two tips a try.

Ah yes, the alias coding ':' does show my Paradox roots, but I found the ':' used in some Delphi example or other and in the absence of any further information thought it worth a try! Out of interest if I did want to use an alias what is the correct syntax to use with Delphi?
Thanks again.
rt

Thats enough of that. Ed.

 Posted 18 years ago (Thread Starter)
Comment Quote
About rt -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About rt

I do like my jazz and blues!


Post ID #8605 (Level 1.2)  Reply to 8588
Reply Posted 12/11/2002 12:47:00 PM
Location=Castel, -- UK 
Joined=20 years ago   MB Posts=687   KB Comments=1  
Most Recent Post
rt
Castel, -- UK
Yes,
>> the BDE is an endangered species these days<<
I think you are right and I must move on to less BDE specific stuff.
rt

Thats enough of that. Ed.

 Posted 18 years ago (Thread Starter)
Comment Quote
About rt -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About rt

I do like my jazz and blues!


Post ID #8614 (Level 1.3)  Reply to 8588
Reply Posted 12/12/2002 6:38:00 AM
Location=Castel, -- UK 
Joined=20 years ago   MB Posts=687   KB Comments=1  
Rick Carter
Cincinnati OH USA

Query1.SQL.Add('FROM ":Contract:Client.db"'); // the Alias

Aha! That looks like a query created in Paradox for Windows, and pasted in. I'm not sure the alias is being passed properly this way, and, in any case, it might be best to get into the habit of writing SQL that will still work if and when you need to move to a different database engine.

Rather than giving the alias this way, I'd suggest that you either assign the path to Query1.DatabaseName, or (my preference) get the path as a string and pass the full path in your SQL (and use single backslashes, rather than the double backslashes you've grown used to using in Paradox).

As another debugging trick, temporarily add a memo to your form, and add the line:
Memo1.Lines := Query1.SQL; 
This will allow you to see just what SQL statement is being passed, which may be different from what you think.
Rick Carter
Chair, Delphi/Paradox SIG
Cincinnati PC Users Group
 Posted 18 years ago
Comment Quote
About Rick Carter -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8602 (Level 1.4)  Reply to 8588
Reply Posted 12/11/2002 10:19:00 AM
Location=Cincinnati OH USA  
Joined=19 years ago   MB Posts=518  
Rick Carter
Cincinnati OH USA
I should clarify that I don't know for a fact that it's a problem to use ":Contract:Client.db" in your code. SQL is passed back to the database engine for processing, so it may be that the BDE can understand something like that just fine. I just know I've never tried it that way in Delphi, and as a general principle I try to find ways to code things that are not specific to the database engine.

Like you, I've invested a lot of time and effort in learning to work with the BDE, and I've got a lot of BDE-specific code I'm still maintaining. But it may be time to realize that the BDE is an endangered species these days.
Rick Carter
Chair, Delphi/Paradox SIG
Cincinnati PC Users Group
 Posted 18 years ago
Comment Quote
About Rick Carter -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8613 (Level 1.5)  Reply to 8588
Reply Posted 12/12/2002 5:10:00 AM
Location=Cincinnati OH USA  
Joined=19 years ago   MB Posts=518  
Larry Drews
Iowa
rt,

"And the question is: What comes before "Index out of bounds(List(1))"?"

Seriously, what does the SQL look like? What does the section of code where you are setting up the parameters and executing the query look like?
 Posted 18 years ago
Comment Quote
About Larry Drews -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About Larry Drews
Veteran software developer specializing in Delphi/Kylix development. Currently Manager of Applications Development for a biotech company in Iowa.

Post ID #8593 (Level 1.6)  Reply to 8588
Reply Posted 12/10/2002 9:37:00 AM
Location=Iowa  
Joined=18 years ago   MB Posts=67   KB Comments=1  
Larry Drews
Iowa
rt,

Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add ('SELECT *');
Query1.SQL.Add ('FROM Client.db');
Query1.SQL.Add('FROM ":Contract:Client.db"'); // the Alias
Query1.Params[0].AsString := edit1.Text; // not working
// Query1.SQL.Add('WHERE Months = ''' + edit1.Text + ''''); //this works
Query1.Open;

The code that you posted must be a little bit garbled, but I think I see what you are trying to do. I think you are misusing the quotes. Your code should look like:

Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add ('SELECT *');
Query1.SQL.Add ('FROM Client.db');
Query1.SQL.Add('WHERE Months = :Months');

Query1.ParamByName('Months').AsString := Edit1.Text;

Query1.Open;

I always feel more comfortable using the ParamByName property rather than Params[x]. Also, please remember that the ':' is the signal to Delphi that the token is a parameter.

Hope this helps.
 Posted 18 years ago
Comment Quote
About Larry Drews -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About Larry Drews
Veteran software developer specializing in Delphi/Kylix development. Currently Manager of Applications Development for a biotech company in Iowa.

Post ID #8600 (Level 1.7)  Reply to 8588
Reply Posted 12/11/2002 6:17:00 AM
Location=Iowa  
Joined=18 years ago   MB Posts=67   KB Comments=1  
Larry Drews
Iowa
rt,


Ah yes, the alias coding ':' does show my Paradox roots, but I found the ':' used in some Delphi example or other and in the absence of any further information thought it worth a try! Out of interest if I did want to use an alias what is the correct syntax to use with Delphi?

If you are using BDE components (which I think you are) then all of those components require you to specify a database name in a form depending on the type of database that you are using. One option is the provide a BDE alias as the database name. This is where you use your alias.

Read up on TDatabase, TTable.DatabaseName, TQuery.Databasename, etc. in the Delphi Help.
 Posted 18 years ago
Comment Quote
About Larry Drews -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About Larry Drews
Veteran software developer specializing in Delphi/Kylix development. Currently Manager of Applications Development for a biotech company in Iowa.

Post ID #8607 (Level 1.8)  Reply to 8588
Reply Posted 12/11/2002 3:27:00 PM
Location=Iowa  
Joined=18 years ago   MB Posts=67   KB Comments=1  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P156A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #8588 Counter
2685
Since 4/2/2008

Follow PrestwoodBoards on: 


©1995-2020 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech