I am creating a Delphi form and want to assign background color to it on run time. This code:
Form1.Color := clSkyBlue;
works well. My problem is that I have stored the color name in a table as a string. So, when I fetch the color name from the table and assign it to Form1.Color, the above statement becomes:
var
ColorName: string;
....
Form1.Color := ColorName;
and this results in a compile time error.
How can I convert a string to a TColor value?
You can use the following conversion functions (both works with color constants):
StringToColorfunction use to translate a string representation of a color toTColorvalueColorToStringfunction use when you need to translateTColorvalue to a string representationIn your case you need to use the
StringToColorfunction: