Solved

quick q

Posted on 2001-07-31
15
147 Views
Last Modified: 2010-08-05
hi,

can anyone correct this code :|

var
n:integer;
begin
for N := 1 to 18 do
panel1.color:=StringToColor(listbox1.Items.Names[n]);

listbox1 has color names eg clred about 18 different colors and when i click on the listbox it gives me an error saying " is not a valid integer.

cheers
classic_gaming
0
Comment
Question by:classic_gaming
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +4
15 Comments
 
LVL 6

Expert Comment

by:edey
ID: 6337986
try 0 to 17

Gl
Mike
0
 
LVL 2

Expert Comment

by:Drareg
ID: 6338022

The first element of a TListBox ( or TStringList, etc. ) has an index of 0, the second element has the index = 1, etc.
So, edey is right.  If you write
For N := 0 To 17 Do...  will work
Or
For N := 0 To ListBox1.Iems.Count - 1 Do ...

0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6338082
hello,

edey is right . but it is not your problem , you have a wrong Color Name in that Listbox1.

it means at first you must check all listbox1 color names. when u corrected the wrong color name you must also change ( 1 to 18 ) to (0 to 17) for solve the message 'list index out of bound' problem

best regards
hamed
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6338089
more clear : 'is not a valid integer' error message is becouse of wrong color name in your listbox. but it is not ur just mistake you must also do that edey & Drareg for solve ur futare problem with error message 'list index out of bound'
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6338176
Hello

  Check your listbox items, i think you have empty item
 the error message " is not a valid integer, mean that you have an item in ur list box empty, and you are trying to change the color to that name, so go to the items in ur listbox, and delete all the empty lines

Mohammed
0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6339282
hi Mohammed , Insha Allah you are fine.

if there was some items in the ListBox1 but one of them was bad name for example clrde instead of clred it makes this error message. but if the listbox1 was empty an error occured when he want to read an item with title 'list index out of bound' becouse it is an reading error but i think the exception call with StringToColor function. are you agree with me.

did you recieve my last email . did you think about my suggestion ( at the end of email )?

Salam
hamed
0
 

Expert Comment

by:d32coder
ID: 6339550
Instead of Items such as clRed, use the $000000 numbers.  Then you can skip the conversion process.

Don
0
 

Author Comment

by:classic_gaming
ID: 6339571
0 to 17 still gives an error.

var
n:integer;
begin
for N := 0 to listbox1.SelCount dopanel1.color:=StringToColor(listbox1.Items.Names[n]);

that dont give errors now.... but do i need to create if files for the 0 to the last number?

cheers
classic_gaming
0
 
LVL 2

Expert Comment

by:Felixin
ID: 6339700
Agreeing with what has been said about the index (it should be from 0 to 17) and presuming that the Items that you have stored are not like "clRed=RedColor", but they are "clRed", then you should use

var
  n:integer;
begin
  for N := 0 to 17 do
    panel1.color:=StringToColor(listbox1.Items [n]);
end;                                     **********

This

panel1.color:=StringToColor(listbox1.Items.Names[n]);

only works with strings like "RedColor=clRed",

where "RedColor" is the name and "clRed" is the value.

The error comes you don't have "Names", I mean, there is no left part of the string with the form "AName=".



0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 70 total points
ID: 6339982
Hello
what do you want to exactly?

  is what you are looking is to change the panel color to the color that u select in the list box?, if that just this line will work with u

 Panel1.Color:=StringToColor(Listbox1.Items.Strings[ListBox1.ItemIndex]);

if not, try to change ur code to this

var
  n:integer;
begin
for N := 0 to listbox1.items.Count -1 do
 Panel1.Color:=StringToColor(Listbox1.Items.Strings[ListBox1.ItemIndex]);


Start ur loop with 0 to the all items in the listbox
and use
Listbox1.Items.Strings
instead of
Listbox1.Items.Names

Mohammed
0
 
LVL 6

Expert Comment

by:edey
ID: 6340521
Felixin, though your comment may contain an actual answer, I think it's prob. not original/conclusive enough to merit being an "answer".

GL
Mike
0
 
LVL 2

Expert Comment

by:Felixin
ID: 6343700
I may be wrong, but I understood that he wanted to correct the code, and the only problem I see is the access to the Names property in an TStrings, and the index question that you pointed at the begining.

I would like to know why the answer has been rejected, what is wrong whit it, even if I respect the decision and respect and thank your comments, Edey.

0
 

Author Comment

by:classic_gaming
ID: 6343713
hi,

Felixin i found mnasman code more helpful and i've even got the code to work let me post the code:

var
n,n1:integer;
s:string;
begin
for N := 0 to listbox1.items.Count -1 do
N1:=StringToColor('cl'+Listbox1.Items.Strings[ListBox1.ItemIndex]);
s:=inttostr(N1);
panel1.color:=stringtocolor(s);

i just made a color turn into a string then back to a int then back to a string and it worked fine :-)

so mnasman you get the points
thanks for all the help
classic_gaming
0
 

Author Comment

by:classic_gaming
ID: 6343717
all i need to do was change a few bits and it worked fine :-)
0
 

Expert Comment

by:d32coder
ID: 6348962
 Colors := array [1..16] of TColor;

  In retrospect, that would have been a good starting point.

  Panel1.Color := Colors[x];
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month4 days, 22 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question