Setting Font Color

In the detail line of a report, I want to set the font color based on a color value stored in a separate field in the detail record. I don't want to display the separate field, just use it to set the font color of the displayed field. Like this...

Record
Value 1
Value 2
Font Color

Set the text of Value 1 to the color contained in Font Color.

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 10:05AM
    write code in obp event of band or memoview to test value and set memoviews .font.fontcolor or
    set up the conditional highlighting
  • edited 10:05AM
    Sorry to be dense, but how do I reference a field in the record set that is not printed on the report?
  • gordkgordk St.Catherines On. Canada.
    edited 10:05AM
    as long as a dataset has been made available to the report it's fields can be referenced
    <datasetname."fieldname">
    record positioning will depend upon band being connected to the dataset or manual positiong
    by code.

    typical code of an obp event of a databand.
    if <datasetname."fieldname"> = 1 then memo1. propertyname := whatever value required.
  • edited 10:05AM
    OK. Here is what I am trying in the OBP event of the DetailData band (txtReason is the MemoView, frxDBDetail is the dataset assigned to the DetailData band)...

    txtReason.Font.Color := frxDBDetail."DisplayColor";

    and I keep getting an Identifier expected error message.

    I've also tried the following in the OBP event of the MemoView (after assigning the "DisplayColor" data field to the memo view)...

    Memo2.Font.Color := Memo2.Value;

    but that doesn't seem to work either (aside from the fact that I don't want to display the actual "DisplayColor" value in the report).

    So what am I missing here?
  • edited 10:05AM
    Upon further testing

    Memo2.Font.Color := Memo2.Value;

    does set the color of the font, but uses the value of the previous record, not the current record.

    (In case I didn't mention it before - the color is user selected and so can be any value. I'm not trying to set the font Red on one condition and Blue on another. I'm trying to set the font to the color the user selected and stored in a data record.)
  • gordkgordk St.Catherines On. Canada.
    edited 10:05AM
    first of all what is the user storing in the reason field an interger, string, or hexvalue.
    also be carefull when and where you use the value property of a memoview's memo
    value returns the value of the last variable or datafield processed in the memo.
  • edited 10:05AM
    The color value for the Reason is stored as an integer value (as returned by a Delphi TColorBox component) and associated with the Reason. The report is a listing of dates an employee was not at work, including the date and the Reason. I want to print the Reason text in the color that was selected by the user and assigned to the Reason.

    So how would I go about doing this?
  • gordkgordk St.Catherines On. Canada.
    edited 10:05AM
    gordon make sure that the reason field is returning an integer and use a case statement in the obp event to decide which color
    ie
    databand1____________________________ connected to ds1 with 2memoviews
    | memo1 | | memo2 |
    [ds1."empid"] [ds1."reasontxt"]

    typical code
    var mycolor:integer;
    procedure databand1OnBeforePrint(Sender: TfrxComponent);
    begin
    mycolor := <ds1."color">;
    case mycolor of
    1:
    begin
    memo2.font.color := clred;
    end;
    2:
    begin
    memo2.font.color := clmaroon;
    end;
    // repeat for each color possibility of color box
    end;
    begin

    end.

    i would temporarily display in a third memo the [ds1."color"] field
    to see what values it is returning.
    you might get a suprise as to what the underlying field actually is returning
  • edited 10:05AM
    Ahh... I was missing the angle brackets around the dataset field name. I was using mycolor := ds1."color" instead of mycolor := <ds1."color">.

    Thanks.

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.