?
Solved

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

Posted on 2009-02-09
19
Medium Priority
?
837 Views
Last Modified: 2013-11-23
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'
0
Comment
Question by:DaveAM
  • 10
  • 8
19 Comments
 
LVL 22

Expert Comment

by:pivar
ID: 23589268
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
 
LVL 22

Expert Comment

by:pivar
ID: 23589274
Sorry, missed the alpha info

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

0
 

Author Comment

by:DaveAM
ID: 23589338
Thanks

I can now get the item colored but it is the same color, irespective of the db entry
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 22

Expert Comment

by:pivar
ID: 23589355
Can you send the code where you like to color the item?
0
 

Author Comment

by:DaveAM
ID: 23589382
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
 
LVL 22

Expert Comment

by:pivar
ID: 23589440
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
 

Author Comment

by:DaveAM
ID: 23590171
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
 
LVL 22

Expert Comment

by:pivar
ID: 23590887
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
 

Author Comment

by:DaveAM
ID: 23591599
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
 
LVL 22

Expert Comment

by:pivar
ID: 23594991
Can you break at the BorderColor := RGB(.... line and tell me what the value of sColor is?
0
 

Author Comment

by:DaveAM
ID: 23595241
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
 
LVL 22

Expert Comment

by:pivar
ID: 23595412
What is the value of BorderColor after assigning RGB?
0
 

Author Comment

by:DaveAM
ID: 23595590
Many thanks

the above delphi Tcolor $009998FF  appears as a grass green
0
 

Author Comment

by:DaveAM
ID: 23595614
Sorry Pivar just a follow up to your last question


All Tcolors appear as shades of green except red it appears as Black
0
 

Author Comment

by:DaveAM
ID: 23595827
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
 
LVL 22

Expert Comment

by:pivar
ID: 23598321
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
 
LVL 2

Accepted Solution

by:
Bongos earned 2000 total points
ID: 23598409
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
 

Author Closing Comment

by:DaveAM
ID: 31544453
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
 

Author Comment

by:DaveAM
ID: 23618423
Sorry on last comment many thanks Bongos, I do appologise.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

862 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