Making child invisible if memo has no text
I am creating a report on runtime. Masterdata has a TfrxChild attached which shows additional text where applicable.
The TfrxChild is created as follows:
The CommentAfterData procedure is created as follows (BuildCommentProcedure):
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?
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
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.