Delphi TColor held in DB Table as string, when i try to read value from DB Table i get an error

How can i get a colour value in a Database to be read by delphi as a TColor ie

The Value $00FF4AFF is held as a string in SQL server Table, but when i try to read the value from the DB table into program like
BorderColor:=dataModule1.Services_Table.FieldByName('Color_Value').AsString;
The following message appears
[DCC Error] Main.pas(280): E2010 Incompatible types: 'TColor' and 'string'
DaveAMAsked:
Who is Participating?
 
BongosConnect With a Mentor Commented:
Can you not use the functions from Graphics unit as below?...., they work fine for me.....

read from dataset...
        ReadOnlyColor := StringToColor(FieldByName('read_only_color').AsString);
and set by stored proc...
        ParamByName('@read_only_color').Value := ColorToString(ReadOnlyColor);
0
 
pivarCommented:
Hi,

Check this link:

http://delphi.about.com/cs/adptips2001/a/bltip0301_5.htm


sColor := dataModule1.Services_Table.FieldByName('Color_Value').AsString;
BorderColor:= RGB(StrToInt('$'+Copy(sColor, 1, 2)), StrToInt('$'+Copy(sColor, 3, 2)), StrToInt('$'+Copy(sColor, 5, 2))) ;

/peter

0
 
pivarCommented:
Sorry, missed the alpha info

BorderColor:= RGB(StrToInt('$'+Copy(sColor, 3, 2)), StrToInt('$'+Copy(sColor, 5, 2)), StrToInt('$'+Copy(sColor, 7, 2))) ;

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
DaveAMAuthor Commented:
Thanks

I can now get the item colored but it is the same color, irespective of the db entry
0
 
pivarCommented:
Can you send the code where you like to color the item?
0
 
DaveAMAuthor Commented:
Sorry hope this helps

Thanks for all help
var
Sib, Sie, Sip, EndTime :Integer;//Sib Select Item Begin,  Sie Select Item End
TT, HBT              :Integer; //TT Total Time, HBT Hair Book Time
Bor_Color, Tra_Color, sColor  :string;
begin
 
Sib:=HairPlanner.SelItemBegin;
Sie:=HairPlanner.SelItemEnd;
Sip:=HairPlanner.SelPosition;
HBT:=datamodule1.Hair_Timing_Table.FieldByName('Hair_Book_Timing').Asinteger;
TT:= datamodule1.Hair_Services_Table.FieldByName('Time_Taken').AsInteger;
Bor_Color:=dataModule1.Hair_Services_Table.FieldByName('Color_Value').AsString;
sColor := dataModule1.Hair_Services_Table.FieldByName('Color_Value').AsString;
//Tra_Color:=dataModule1.Hair_Services_Table.FieldByName('Color_Value').CurValue;
Endtime:=(TT div HBT);
BDSTrue:=False;
      if NOT (HairPlanner.Items.HasItem(Sib,Sie,Sip) OR  HairPlanner.Items.HasItem(Sib,Sie,Sip))then
            with HairPlanner.CreateItemAtSelection do
              if StrToInt(ClientNoEdit1.Text)<=1 then
                  Begin
                    PlanItem2TF:=False;
                    PlanItem1TF:=False;
                    //BorderColor:=StringToColor (dbcolorV.Text);
                    BorderColor:= RGB(StrToInt('$'+Copy(sColor, 3, 2)), StrToInt('$'+Copy(sColor, 5, 2)), StrToInt('$'+Copy(sColor, 7, 2))) ;
                    //TrackColor:=dataModule1.Hair_Services_Table.FieldByName('Color_Value').Asstring;
                    ItemEnd:=ItemEnd + EndTime;
                    CaptionText:=HName.Text;
                    Text.Add(dataModule1.Hair_Services_Table.FieldByName('Short_Name').AsString);
                    Text.add(HTel.Text);
                    HairPlanner.Update;
                    Update;
                  End;
sColor:='';//I Just added this 
end;

Open in new window

0
 
pivarCommented:
What is it you coloring? The border of HairPlannerItem (what type of component is it)? Does it always change to the same color? And you're sure there is different color values in db? Have you checked with messagebox, debugoutput or something?
0
 
DaveAMAuthor Commented:
sorry
The Planner  is a graphic representation of a diary page, each item is an appointment.  Each appointment dependent on service can have a set color as in the data base table, this can be set by the user from a color dialog box.  When an appointment is picked as in service, the color is then sent to th planner item as a border color
0
 
pivarCommented:
I'm sorry, to me it looks alright, although I'm not familiar with the component. As I said please check that the return value from RGB to BorderColor is correct, either by MessageBox or Debugoutput.
0
 
DaveAMAuthor Commented:
Sorry Pivar
BorderColor is showing color if i mess with the RGB Values as in changing the  first value after sColor I can change the colors of the border but not to the color held in the DB Field
 BorderColor:= RGB(StrToInt('$'+Copy(sColor, 3, 2)), StrToInt('$'+Copy(sColor, 5, 2)), StrToInt('$'+Copy(sColor, 7, 2))) ;

Open in new window

0
 
pivarCommented:
Can you break at the BorderColor := RGB(.... line and tell me what the value of sColor is?
0
 
DaveAMAuthor Commented:
The value of sColor is the same as the db field of the table.
I set an edit box to hold the contents of sColor  $009998FF  
0
 
pivarCommented:
What is the value of BorderColor after assigning RGB?
0
 
DaveAMAuthor Commented:
Many thanks

the above delphi Tcolor $009998FF  appears as a grass green
0
 
DaveAMAuthor Commented:
Sorry Pivar just a follow up to your last question


All Tcolors appear as shades of green except red it appears as Black
0
 
DaveAMAuthor Commented:
Many thanks Pivar
After trial and error, not the best way to program though, I tried many combinations but this seemed to work best.  Please comment if you would make any changes
The colors appear true on screen.

RGB(StrToInt('$'+Copy(sColor, 7, 3)), StrToInt('$'+Copy(sColor, 5,3)), StrToInt('$'+Copy(sColor, 5,2))) ;

thanks again in advance.
0
 
pivarCommented:
I would not recommend you to do like that. Because you're not creating correct colors according to the rgb standard that you have stored in the db. If you think the colorvalues in the db are wrong, then change it in the db and use the correct rgb creation command:
 
BorderColor:= RGB(StrToInt('$'+Copy(sColor, 3, 2)), StrToInt('$'+Copy(sColor, 5, 2)), StrToInt('$'+Copy(sColor, 7, 2))) ;

This would give a TColor 16750745  with the value $009998FF and it should be light blue.
0
 
DaveAMAuthor Commented:
Thanks Pivar, had to get my head round the graphics and colour settings, but everything works great.  I have now written an SQL statement to pull from the database
0
 
DaveAMAuthor Commented:
Sorry on last comment many thanks Bongos, I do appologise.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.