Asign color to text by data field

HedleyHedley Peru
edited 4:28AM in FastReport 4.0
Hi..

i use this sentences to asign color to text

procedure alum1mAS1OnBeforePrint(Sender: TfrxComponent);
begin
if <alumE."AS1">='7' then alum1mAS1.font.color:=clBlack
else if <alumE."AS1">='8' then alum1mAS1.font.color:=clMaroon
else if <alumE."AS1">='5' then alum1mAS1.font.color:=clRed
else if <alumE."AS1">='6' then alum1mAS1.font.color:=clGreen
else if <alumE."AS1">='9' then alum1mAS1.font.color:=clNavy
else if <alumE."AS1">='10' then alum1mAS1.font.color:=clNavy
else alum1mAS1.font.color:=clRed
end;

and this is for 20 fields, and for 25 records... then ... 500 at last

if the colors change, i need to change the sentences...

is posible that the "color" will be a another field in the data

alum1mAS1.font.color := colorfromdata ( clblack/clMaroon/clRed/clNavy ....... )

Thanks a lot

Hedley

Comments

  • Anu de DeusAnu de Deus Hampshire, UK
    edited 4:28AM
    Sure.
    Font.color is a cardinal value, this is for example is black:
    alum1mAS1.font.color:= 0;

    And this is red:
    alum1mAS1.font.color:= $0000FF; // or 255;

    So, what you need is a field (integer type) with the color value:

    alum1mAS1.font.color:= <alumE."DataColor">;

    Or at even a function that calculates it for you:
    alum1mAS1.font.color:= GetTheColor(<alumE."AS1">);

    function GetTheColor(pData: variant): DWORD;
    var lData: integer;
    begin
    lData:= vartoint(pData);
    case lData of
    0: result := 0;
    1: result := $33;
    etc...
    end;

    end;

  • HedleyHedley Peru
    edited 4:28AM
    Anu de Deus :

    thanks a lot...

    but how i know the cardinals number for the other colours

    may be i use a numbers code from html text ?

    thanks again...

    Hedley
  • Anu de DeusAnu de Deus Hampshire, UK
    edited 4:28AM
    Yes, try using the same codes as HTML.
    However, it's possible that they are coded inversely (RGB instead of BGR), so put as many colors as you can and test it.
    If the codes are inverted, you can convert it, but I'm not going to teach you how to do that, you will have to do a bit of research (and learning...)
  • HedleyHedley Peru
    edited 4:28AM
    thanks... i will try...

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.