DaveAM
asked on
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.S ervices_Ta ble.FieldB yName('Col or_Value') .AsString;
The following message appears
[DCC Error] Main.pas(280): E2010 Incompatible types: 'TColor' and 'string'
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.S
The following message appears
[DCC Error] Main.pas(280): E2010 Incompatible types: 'TColor' and 'string'
Sorry, missed the alpha info
BorderColor:= RGB(StrToInt('$'+Copy(sCol or, 3, 2)), StrToInt('$'+Copy(sColor, 5, 2)), StrToInt('$'+Copy(sColor, 7, 2))) ;
BorderColor:= RGB(StrToInt('$'+Copy(sCol
ASKER
Thanks
I can now get the item colored but it is the same color, irespective of the db entry
I can now get the item colored but it is the same color, irespective of the db entry
Can you send the code where you like to color the item?
ASKER
Sorry hope this helps
Thanks for all help
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;
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?
ASKER
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
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
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.
ASKER
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 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))) ;
Can you break at the BorderColor := RGB(.... line and tell me what the value of sColor is?
ASKER
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
I set an edit box to hold the contents of sColor $009998FF
What is the value of BorderColor after assigning RGB?
ASKER
Many thanks
the above delphi Tcolor $009998FF appears as a grass green
the above delphi Tcolor $009998FF appears as a grass green
ASKER
Sorry Pivar just a follow up to your last question
All Tcolors appear as shades of green except red it appears as Black
All Tcolors appear as shades of green except red it appears as Black
ASKER
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(sCol or, 7, 3)), StrToInt('$'+Copy(sColor, 5,3)), StrToInt('$'+Copy(sColor, 5,2))) ;
thanks again in advance.
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(sCol
thanks again in advance.
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(sCol or, 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.
BorderColor:= RGB(StrToInt('$'+Copy(sCol
This would give a TColor 16750745 with the value $009998FF and it should be light blue.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
ASKER
Sorry on last comment many thanks Bongos, I do appologise.
Check this link:
http://delphi.about.com/cs/adptips2001/a/bltip0301_5.htm
sColor := dataModule1.Services_Table
BorderColor:= RGB(StrToInt('$'+Copy(sCol
/peter