how to convert TColor to TCanvasColor array's etc lazarus / 39-Graphics ---------------------------------------------------------------------- userx-bw · 2014-02-03 16:08 I am trying to make an array of colors (mostly just system colors) in order to perform a RANDOM effect on them then picking one color randomly then setting it as the color picked. I am in the just trying to figure it out stage of my procedure / function as i still have to figure out how to use it in a Thread. I am assuming that this is a type of an Array of sorts, therefore it should have elements that I can even call if I want to as such. Code: [Select]type  TColor = (   clBlack,   clMaroon,   clGreen,   clOlive,   clNavy,   clPurple,   clTeal,   clGray,   clSilver,   clRed,   clLime,   clYellow,   clBlue,   clFuchsia,   clAqua,   clLtGray, // clSilver alias   clDkGray, // clGray alias   clWhite   );   TColors = set of TColor;                               making that an Array Object of sorts. when I do this Code: [Select]procedure TForm1.Button1Click( Sender: TObject) ; var   Colors: TColor; begin   //for Colors in TColor do    // begin     shape1.Brush.Color:=Colors[2];   // end; end; i get an error Code: [Select]unit1.pas(65,32) Error: Illegal qualifier Code: [Select]procedure TForm1.Button1Click( Sender: TObject) ; var   Colors: TColor; begin   for Colors in TColor do     begin     shape1.Brush.Color:=TColorToFPColor(Colors);    end; end;    I get an error Code: [Select]unit1.pas(64,47) Error: Incompatible type for arg no. 1: Got "TColor", expected "TGraphicsColor" the example I used tells me nothing really Quotetype   TColor = (cRed, cGren, cBlue);   TColors = set of TColor; procedure SetLoop(Colors: TColors); var   Color: TColor; begin   for Color in Colors do     DoSomething(Color); end; I tried the cRED, cBLUE, then changed it to clRED, clBLUE. putting the cl back still errors. in the properties of the shape object it just reads clColor if you put in the code. Code: [Select]shape.Brush.Color:=clYellow; Code: [Select]unit1.pas(64,33) Error: Incompatible type for arg no. 1: Got "TColor", expected "TGraphicsColor" I get errors. WHY? mod: I just tried this too as per the web page http://wiki.freepascal.org/Colors Code: [Select] TColor = (   ($000000),   $000080,   $008000,   $008080,   $800000,   $800080,   $808000,   $808080,   $C0C0C0,   $0000FF,   $00FF00,   $00FFFF,   $FF0000,   $FF00FF,   $FFFF00,   $C0C0C0,   $808080,   $FFFFFF   ); ---------------------------------------------------------------------- taazz · 2014-02-03 16:17 because TColor is already declared and by defining a tcolor type in your unit you override the correct one which is used by all the other lcl units and they know nothing about your type. How about this Code: [Select]const   MyColors : array[0..2] of TColor = (clBlue, clRed, clGreen); Try using that array and extend it to support as many colors as you like. ---------------------------------------------------------------------- userx-bw · 2014-02-03 16:44 Quote from: taazz on February 03, 2014, 05:17:41 pmbecause TColor is already declared and by defining a tcolor type in your unit you override the correct one which is used by all the other lcl units and they know nothing about your type. How about this Code: [Select]const   MyColors : array[0..2] of TColor = (clBlue, clRed, clGreen); Try using that array and extend it to support as many colors as you like. that was my original thinking but I used Lazarus example instead ... http://wiki.freepascal.org/for-in_loop Code: [Select]type   TColor = (cRed, cGren, cBlue);   TColors = set of TColor; procedure SetLoop(Colors: TColors); var   Color: TColor; begin   for Color in Colors do     DoSomething(Color); end;resetting thought process to original thought thanks ---------------------------------------------------------------------- taazz · 2014-02-03 16:55 yes that is an example on how to use the for X in Y loop construct it has nothing to do with the Tcolor and the array of colors you want, try something like this, Code: [Select] Procedure WriteLNColors(const aColors : Array of TColor); var   vColor :TColor; begin   for vColor in aColors do begin       writeln(inttohex(vColor,4));   end; end; begin   writelnColors([clRed, clBlue, clGreen, clGray, clSilver, clSkyBlue, clMaroon, clMoneyGreen, clFuchsia, clCream]); end; ---------------------------------------------------------------------- userx-bw · 2014-02-03 17:54 Quote from: taazz on February 03, 2014, 05:55:46 pmyes that is an example on how to use the for X in Y loop construct it has nothing to do with the Tcolor and the array of colors you want, try something like this, Code: [Select] Procedure WriteLNColors(const aColors : Array of TColor); var   vColor :TColor; begin   for vColor in aColors do begin       writeln(inttohex(vColor,4));   end; end; begin   writelnColors([clRed, clBlue, clGreen, clGray, clSilver, clSkyBlue, clMaroon, clMoneyGreen, clFuchsia, clCream]); end; Ok I got that chunck of code figured out. Code: [Select]   MyColors :  array[0..17] of TColor = (                 clBlack, clMaroon, clGreen, clOlive, clNavy, clPurple, clTeal, clGray, clSilver, clRed, clLime, clYellow, clBlue, clFuchsia, clAqua, clLtGray, clDkGray, clWhite );                            picks a random number 0 to 17 one time each click giving me a random color from the array of TColor Thanks!!! Code: [Select]procedure TForm1.Button2Click( Sender: TObject) ; var   result,i:LongInt;   begin   for i:=1 to 1 do   begin       result := Random(17);        shape1.Brush.Color:=MyColors[result];       shape1.Refresh;   end; end; Thanks! ---------------------------------------------------------------------- taazz · 2014-02-03 23:55 LOL. You seem to have a small disorder with the loops don't you? Why did you obsessively added a "for I" loop were it is not needed? To make sure that it runs exactly once? just remove the loop. You know that an elegant design has been reached not when you can't think of anything else to add but when you can't remove anything else with out compromising features or capabilities. ---------------------------------------------------------------------- userx-bw · 2014-02-04 01:03 Quote from: taazz on February 04, 2014, 12:55:57 amLOL. You seem to have a small disorder with the loops don't you? Why did you obsessively added a "for I" loop were it is not needed? To make sure that it runs exactly once? just remove the loop. You know that an elegant design has been reached not when you can't think of anything else to add but when you can't remove anything else with out compromising features or capabilities. perhaps . I Think I'm just trying to learn too much advanced programming in just what I  need to know  to get this program upgraded so it's  put me in over load so my brain is not thinking everything though.  I try it. it work so I just went to the next thing I need to get done with out thinking it all the way through ...  thanks for the back up LoL ---------------------------------------------------------------------- taazz · 2014-02-04 02:01 Ow! a small case of copypastitis, I see. Been there had that it is something all programmers go through, something like measles, you grow out of it eventually. ---------------------------------------------------------------------- userx-bw · 2014-02-04 02:26 Quote from: taazz on February 04, 2014, 03:01:31 amOw! a small case of copypastitis, I see. Been there had that it is something all programmers go through, something like measles, you grow out of it eventually. copypastitis how could you tell I've been doing a lot of that? ... LoL