Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

quick q

Posted on 2001-07-31
15
Medium Priority
?
151 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 280 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] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

885 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