Display StringGrid in report

I am really struggling with diplaying a StringGrid in a report. I have copied the code from the sample Delphi application and changed it slightly to suit my application as follows.

procedure TfrmViewFormulation.rptFormulationBeforePrint(c: TfrxReportComponent);
var
Cross: TfrxCrossView;
i, j: Integer;
begin
if c is TfrxCrossView then
begin
Cross := TfrxCrossView©;
for i := 1 to 6 do
for j := 1 to 6 do
Cross.AddValue(, [j], [FormulaGrid.Cells[i, j]]);
end;
end;

When I preview the report the data from the StringGrid does not appear. If I add a breakpoint anywhere in the loop

begin
Cross := TfrxCrossView©;
for i := 1 to 6 do
for j := 1 to 6 do
Cross.AddValue(, [j], [FormulaGrid.Cells[i, j]]);
end;

it appears that this loop is never executed. If I put the breakpoint at "if c is TfrxCrossView then" then the execution stops at that point.

What have I missed?

Comments

  • edited 12:41PM
    For some reason after I deleted the report and receated it the grid displayed without any problems.

    My next question is how to change the width of the columns in the crosstab. There is a section in the manual that describes OnCalcWidth but I'm not sure how to add it to my code. I would also like to change the alignment of the cells depending on the column (ie columns 1 - 2 left align, columns 3 - 6 right align).
  • edited 12:41PM
    Have a look at samples below:
    procedure Cross1OnCalcWidth(ColumnIndex: Integer; ColumnValues: Variant; var Width: Extended);
    begin
      case ColumnIndex of                                                           
      0:    Width := 3 * fr1cm;   // 3 cm                         
      1,3:  Width := 2 * fr1cm;   // 2 cm                
      2,4:  Width := 4 * fr1cm;   // 4 cm                
      end;            
    end;
    
    procedure Cross1OnPrintCell(Memo: TfrxMemoView; RowIndex, ColumnIndex, CellIndex: Integer; RowValues, ColumnValues, Value: Variant);
    begin
      case ColumnIndex of                                                           
      0:    Memo.HAlign := haLeft;   // align left                                               
      1,3:  Memo.HAlign := haRight;  // align right                                        
      2,4:  Memo.HAlign := haCenter; // align center                                          
      end;            
    end;
    

    Mick

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.