Hi every one!

Hi every one!
I want to use FastReport with a Database, where the field 'sex' is represented in the DB as '0' for 'male' and '1' for 'female', but I want to print it as 'male' , 'female' not '0', '1'
I asked around and they gave me that code :

procedure TForm1.ADOTable1sexeGetText(Sender: TField; var Text: string;  DisplayText: Boolean);
begin
  if Sender.AsString[1] = '0' then Text := 'Male';
  if Sender.AsString[1] = '1' then Text := 'Female';
end;

but it looks like this code works only with AdoTable, not with AdoQuery

procedure TForm1.ADOQuery1sexeGetText(Sender: TField; var Text: string;  DisplayText: Boolean);
begin
  if Sender.AsString[1] = '0' then Text := 'Male';
  if Sender.AsString[1] = '1' then Text := 'Female';
end;

Any ideas?

Comments

  1. Do you mean FastReport?  If so, I would just use the built-in scripting capability of the report itself to interrogate the field value and substitute it there.

    When in the report editor,  double-click on the output field (TFrxMemoView) in question and add some Pascal script.

    This approach is really handy if your reports are stored externally from the .dfm (e.g. MyReport.fr3), because you can modify and redeploy the report without having to recompile your application.  Example: After deployment, you later decide you want to show M and F in your report instead of Male and Female

    ReplyDelete
  2. Clearly you got the field values reversed:
    Male -> sex = 1
    Female -> sex = 0

    Bad jokes aside, Gender \in ('f', 'm') would be my choice. More explicit and easier to handle edge cases (transgendered people and similar).

    ReplyDelete
  3. Kevin Powick I always think about this way of programming reports! I'll try to find out more how to do it
    Thank you all!

    ReplyDelete
  4. Hi,
    why you don't work with views? You can create in view field with output  - for example:
    CAST 
    WHEN SEX = 0 THEN 'MALE'
    ELSE 'FEMALE'
    END;

    ReplyDelete
  5. procedure Memo9OnBeforePrint(Sender: TfrxComponent);
    begin
      if = '0' then
      Memo9.Text:= 'Male';
      if = '1' then
      Memo9.Text:= 'Female';  
    end;
    Kevin Powick  it works like this :)

    ReplyDelete

Post a Comment