Colors of the rainbow

Ozan K. BAYRAMOzan K. BAYRAM Istanbul
edited 3:43PM in FastReport Server
This is OK, there is no problem.
var
Color1:longint=0;

begin
Color1 := $00F0E3F2;
Memo185.Color:=Color1;
end.

but i need to use hex colors like '#FF0000'.

is there any easy way to convert?

thanks in advance

Comments

  • Ozan K. BAYRAMOzan K. BAYRAM Istanbul
    edited 3:43PM
    after you removed # you can use this method.
    function HexToInt(HexNum: string): LongInt;
    begin
       Result:=StrToInt('$' + HexNum);
    end;
    
  • Ozan K. BAYRAMOzan K. BAYRAM Istanbul
    edited March 2010
    ok... hex to int works great but there is a problem with the color convertion...

    if your color is #AABBCC then you need to convert this as $00CCBBAA...

    Now i'm using these methods to achive that goal... Any suggestion would be appreciated...
    FUNCTION Power(X,Y:Word):LongInt;
    VAR Temp,Teller : LongInt;
    BEGIN
      TEMP:=1;
    
      FOR Teller:=1 TO Y DO
      begin
           TEMP:=TEMP*X;
      end;
      result:=Temp;
    END; { Power }
    
    
    FUNCTION Hex2Dec(Hex:STRING):LongInt;
    VAR   T1,T2,DecimalValue: LongInt;
          Error:Boolean;
    BEGIN
      Error:=False;
      T1:=0;T2:=0;DecimalValue:=0;
      FOR T1:=1 TO LENGTH(Hex) DO
      BEGIN
       T2:=Length(Hex)-T1;
       CASE Hex[T1] OF
       '0'  : DecimalValue:=DecimalValue+0;
       '1'  : DecimalValue:=DecimalValue+Power(16,T2);
       '2'  : DecimalValue:=DecimalValue+2*Power(16,T2);
       '3'  : DecimalValue:=DecimalValue+3*Power(16,T2);
       '4'  : DecimalValue:=DecimalValue+4*Power(16,T2);
       '5'  : DecimalValue:=DecimalValue+5*Power(16,T2);
       '6'  : DecimalValue:=DecimalValue+6*Power(16,T2);
       '7'  : DecimalValue:=DecimalValue+7*Power(16,T2);
       '8'  : DecimalValue:=DecimalValue+8*Power(16,T2);
       '9'  : DecimalValue:=DecimalValue+9*Power(16,T2);
       'A','a' : DecimalValue:=DecimalValue+10*Power(16,T2);
       'B','b' : DecimalValue:=DecimalValue+11*Power(16,T2);
       'C','c' : DecimalValue:=DecimalValue+12*Power(16,T2);
       'D','d' : DecimalValue:=DecimalValue+13*Power(16,T2);
       'E','e' : DecimalValue:=DecimalValue+14*Power(16,T2);
       'F','f' : DecimalValue:=DecimalValue+15*Power(16,T2);
       ELSE Error:=True;
       END;
      END;
      result:=DecimalValue;
      IF Error THEN result:=0;
    END; { Hex2Dec }
    
    //The function is hex colour format convert to fast report format
    // '#ABCDEF' => $00EFCDAB       
    function ConvertColor(Color:string):longint;
    var part1,part2,part3,newhexcode:String;                                                             
    begin
         part3:=Copy(Color,2,2);
         part2:=Copy(Color,4,2);
         part1:=Copy(Color,6,2);
         newhexcode := part1 + part2 + part3;                                                                     
         Result := Hex2Dec(newhexcode);
    end;
    
  • edited March 2011
    ok... hex to int works great but there is a problem with the color convertion...

    if your color is #AABBCC then you need to convert this as $00CCBBAA...

    Now i'm using these methods to achive that goal... Any suggestion would be appreciated...
    FUNCTION Power(X,Y:Word):LongInt;
    VAR Temp,Teller : LongInt;
    BEGIN
      TEMP:=1;
    
      FOR Teller:=1 TO Y DO
      begin
           TEMP:=TEMP*X;
      end;
      result:=Temp;
    END; { Power }
    
    
    FUNCTION Hex2Dec(Hex:STRING):LongInt;
    VAR   T1,T2,DecimalValue: LongInt;
          Error:Boolean;
    BEGIN
      Error:=False;
      T1:=0;T2:=0;DecimalValue:=0;
      FOR T1:=1 TO LENGTH(Hex) DO
      BEGIN
       T2:=Length(Hex)-T1;
       CASE Hex[T1] OF
       '0'  : DecimalValue:=DecimalValue+0;
       '1'  : DecimalValue:=DecimalValue+Power(16,T2);
       '2'  : DecimalValue:=DecimalValue+2*Power(16,T2);
       '3'  : DecimalValue:=DecimalValue+3*Power(16,T2);
       '4'  : DecimalValue:=DecimalValue+4*Power(16,T2);
       '5'  : DecimalValue:=DecimalValue+5*Power(16,T2);
       '6'  : DecimalValue:=DecimalValue+6*Power(16,T2);
       '7'  : DecimalValue:=DecimalValue+7*Power(16,T2);
       '8'  : DecimalValue:=DecimalValue+8*Power(16,T2);
       '9'  : DecimalValue:=DecimalValue+9*Power(16,T2);
       'A','a' : DecimalValue:=DecimalValue+10*Power(16,T2);
       'B','b' : DecimalValue:=DecimalValue+11*Power(16,T2);
       'C','c' : DecimalValue:=DecimalValue+12*Power(16,T2);
       'D','d' : DecimalValue:=DecimalValue+13*Power(16,T2);
       'E','e' : DecimalValue:=DecimalValue+14*Power(16,T2);
       'F','f' : DecimalValue:=DecimalValue+15*Power(16,T2);
       ELSE Error:=True;
       END;
      END;
      result:=DecimalValue;
      IF Error THEN result:=0;
    END; { Hex2Dec }
    
    //The function is hex colour format convert to fast report format
    // '#ABCDEF' => $00EFCDAB       
    function ConvertColor(Color:string):longint;
    var part1,part2,part3,newhexcode:String;                                                             
    begin
         part3:=Copy(Color,2,2);
         part2:=Copy(Color,4,2);
         part1:=Copy(Color,6,2);
         newhexcode := part1 + part2 + part3;                                                                     
         Result := Hex2Dec(newhexcode);
    end;
    




    Thanks you for the post.
    Hi guys, Im a newbie. Nice to join this forum.



    __________________
  • edited 3:43PM
    Hey, Ozan!

    so did you finda solution?
    if you did, could you please pm me and tell what exactly you did?
    i'd really appreciate it, thank you in advance

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.