Solved

quick q

Posted on 2001-07-31
15
140 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
 
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:mnasman
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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:
mnasman 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now