Making child invisible if memo has no text

edited 10:56AM in FastReport 4.0
I am creating a report on runtime. Masterdata has a TfrxChild attached which shows additional text where applicable.
The TfrxChild is created as follows:
frxChild := TfrxChild.Create(Page);
frxChild.CreateUniqueName;
frxChild.Stretched := TRUE;
frxChild.Top := Band.Height+1;
frxChild.Height := 16;
Band.Child := frxChild;        
frxChild.PrintChildIfInvisible := FALSE;
BuildCommentProcedure;
With TfrxMemoView.Create(frxChild) do
Begin
   CreateUniqueName;
   HAlign := TfrxHAlign.haLeft;
   StretchMode  := smActualHeight;
   Dataset := ReportPrint.ReportTable;
   Parent := frxChild;
   SetBounds(0, 0, 180, 16);
   AutoWidth := TRUE;
   DataField := ExtraDescField.FieldName;
   Style := 'Data';
   OnAfterData := 'CommentAfterData';
End;

The CommentAfterData procedure is created as follows (BuildCommentProcedure):
procedure BuildCommentProcedure;
  begin
    ReportPrint.Report.ScriptText.Clear; // clear existing script text
    ReportPrint.Report.ScriptText.Add('procedure CommentAfterData(Sender : TfrxComponent);');
    ReportPrint.Report.ScriptText.Add('Begin');
    ReportPrint.Report.ScriptText.Add('if Sender is TfrxMemoView then');
    ReportPrint.Report.ScriptText.Add('begin ');
    ReportPrint.Report.ScriptText.Add('if (TfrxMemoView(Sender).Parent is TfrxChild) and (TfrxMemoView(Sender).Text = '''') then ');
    ReportPrint.Report.ScriptText.Add('TfrxChild(TfrxMemoView(Sender).Parent).Visible := FALSE ');
    ReportPrint.Report.ScriptText.Add('else TfrxChild(TfrxMemoView(Sender).Parent).Visible := TRUE ');
    ReportPrint.Report.ScriptText.Add('end; ');
    ReportPrint.Report.ScriptText.Add('End; ');

    //Main procedure
    ReportPrint.Report.ScriptText.Add('Begin ');
    ReportPrint.Report.ScriptText.Add('End. ');
  end;

The problem i have is when I run it, the OnAfterData procedure makes all TfrxChilds invisible after it encounters one that is made invisible. I.e. when one has Text = '' then it treats the rest the same, i.e. makes them Visible := FALSE
Any ideas?

Comments

  • edited 10:56AM
    Update on this post.
    Since I had no response I had to rethink this way of making the child invisible. After stepping through the report, it is clear that OnAfterData is not called for invisible components, hence it does not call it again after making the child invisible. I resorted to making the height of child and memoview equal to zero if no text, otherwise equal to default height.

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.