Recent

Author Topic: programaticaly decide which columns are printed ?  (Read 1856 times)

mirce.vladimirov

  • Full Member
  • ***
  • Posts: 220
programaticaly decide which columns are printed ?
« on: February 23, 2015, 04:56:36 pm »
I got a report that has two diferent pages with diferent sets of columns.
Using one query to retrieve all the necesery data.
First page should print the first 30-50 rows with some columns, second page should print the rest of the rows and other columns ffrom the query.
The criteria is the key field, lets say MySQLQuery.fieldbyname('rownum').asinteger.
How can I properly print a two-paged report depending on this column ?
Thanks.

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: programaticaly decide which columns are printed ?
« Reply #1 on: February 23, 2015, 04:57:53 pm »
use a subreport and different where clauses.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

GetMem

  • Hero Member
  • *****
  • Posts: 3506
Re: programaticaly decide which columns are printed ?
« Reply #2 on: February 23, 2015, 05:38:09 pm »
Hi  mirce.vladimirov,

Try something like this, I did not test it, but it should work:

Code: [Select]
var
  FirstPage: Boolean = True;

procedure TForm1.frReport1BeginBand(Band: TfrBand);
begin
  if Band.Typ = btDetailData then //change the bandtype if neccesarry
  begin
    if MySQLQuery.FieldByName('rownum').AsInteger = 30 then //second page starts at row 31
    begin
      FirstPage := False;
      Band.NewPageAfter := True
    end
    else
      Band.NewPageAfter := False;
   end;
end;

procedure TForm1.frReport1EnterRect(Memo: TStringList; View: TfrView);
begin
  if (View is TfrMemoView) then
  begin
    (View as TfrMemoView).FillColor := clWhite;
    if (View as  TfrMemoView).Name = 'mFirstPageMemo' then
    begin
      (View as TfrMemoView).Memo.Clear;
      (View as TfrMemoView).Memo.Add(MySQLQuery.FieldByName('FirstPageColumn').AsString);
      (View as TfrMemoView).Visible := FirstPage;
      Exit;
    end;
    if (View as TfrMemoView).Name = 'mSecondPageMemo' then
    begin
      (View as TfrMemoView).Memo.Clear;
      (View as TfrMemoView).Memo.Add(MySQLQuery.FieldByName('SecondPageColumn').AsString);
      (View as TfrMemoView).Visible := not FirstPage;
      Exit;
    end;
  end;
end;

regards,
GetMem