Color a field by color in nother field

HedleyHedley Peru
edited 4:26AM in FastReport 4.0
i have 2 fields in a table

alume
as1 char 3
as1c char 10

example
as1 value is 5
as1c value is clBlue

Memo alumEAS1 contains [alumE."AS1"]

procedure DetailData1OnBeforePrint(Sender: TfrxComponent);
begin
alumEAS1.font.color := <alumE."AS1C">
end;

i obtain an error "could not convert variant of type (string) into type (boolean)

what i am doing wrong ?

how it would be right

thanks

hedley

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 4:26AM
    hedley
    font colors are colorconstants clred.claqua, etc. not strings so try
    alumEAS1.font.color := (<alumE."AS1C">)
  • HedleyHedley Peru
    edited 4:26AM
    gordk wrote: »
    hedley
    font colors are colorconstants clred.claqua, etc. not strings so try
    alumEAS1.font.color := (<alumE."AS1C">)

    Dear gordk : i tried but i obteained the same mess error

    could not convert variant of type (string) into type (boolean)

    thanks
  • gordkgordk St.Catherines On. Canada.
    edited 4:26AM
    are you sure you did not type = in place of :=
  • gordkgordk St.Catherines On. Canada.
    edited 4:26AM
    Hedley it is due to the fact that you are storing the color as a string and the delphi stringtocolor function
    is not available in the internal functionsyou can work around this by either adding the function in a function lib, or using variables set on to the color field and one with no value at all
    use the one with no value in report code to trigger the ogv event indelphi then use the delphifunction to return the color.
  • Anu de DeusAnu de Deus Hampshire, UK
    edited 4:26AM
    You have 2 options, but both will mean you have to change your code or your table definition:
    1) change the field type to longint or equivalent, store the the Tcolor value there, for example, dataset.fieldbyName('AS1C') := clBlue (or whatever color it is), and your line alumEAS1.font.color := <alumE."AS1C"> should work, if not, try
    alumEAS1.font.color := cardinal(<alumE."AS1C">);
    or
    alumEAS1.font.color := TColor(<alumE."AS1C">);

    Actually, try alumEAS1.font.color := TColor(<alumE."AS1C">); in your current code without changing the field definition anyway, maybe it will work.

    2) If you can't change the field definition for whatever reason, create an IF...THEN to analyse each string case in your BeforePrint event:
    if <alumE."AS1C"> = 'clBlue' then
    alumEAS1.font.color := clBlue
    else
    if <alumE."AS1C"> = 'clRed' then
    alumEAS1.font.color := clRed
    else ...


    Cheers, Alex
  • HedleyHedley Peru
    edited 4:26AM
    You have 2 options, but both will mean you have to change your code or your table definition:
    1) change the field type to longint or equivalent, store the the Tcolor value there, for example, dataset.fieldbyName('AS1C') := clBlue (or whatever color it is), and your line alumEAS1.font.color := <alumE."AS1C"> should work, if not, try
    alumEAS1.font.color := cardinal(<alumE."AS1C">);
    or
    alumEAS1.font.color := TColor(<alumE."AS1C">);

    Actually, try alumEAS1.font.color := TColor(<alumE."AS1C">); in your current code without changing the field definition anyway, maybe it will work.

    2) If you can't change the field definition for whatever reason, create an IF...THEN to analyse each string case in your BeforePrint event:
    if <alumE."AS1C"> = 'clBlue' then
    alumEAS1.font.color := clBlue
    else
    if <alumE."AS1C"> = 'clRed' then
    alumEAS1.font.color := clRed
    else ...


    Cheers, Alex


    Alex :

    1. in cardinal and Tcolor, i receive the message "too many parameters"

    2. i'll do this, but i have about 50 fields to test and assign color, and it's a litle slow, and take about 5 seconds to display te report. this is why i tried to change the way to do it more parametric and faster

    thanks

    hedley
  • gordkgordk St.Catherines On. Canada.
    edited 4:26AM
    hedley much easier to create the function lib and use it
    then code would look like
    memo#.font.color := mycolor(<datasetname."fieldname">);
  • HedleyHedley Peru
    edited 4:26AM
    gordk wrote: »
    hedley much easier to create the function lib and use it
    then code would look like
    memo#.font.color := mycolor(<datasetname."fieldname">);


    Gordk :

    would you send me some tips to create the function lib ?

    thanks

    hedley
  • gordkgordk St.Catherines On. Canada.
    edited 4:26AM
    see the developers manual build the functions store in a .pas file add the unit to forms uses clause and they will be available at runtime.
    if you want to have them available from with in the ide build it as a component
    good example is Stalker's additional function lib in the Binaries news group

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.