How tos

How To create a report which is based on a temporary table?

Author
Luc Van Dyck
Date
16/05/2003
Size
4,07 KB
Downloads
3656
Rating
43211
Popularity
Downloaded 5 times in the last two weeks
When you normally create a report, it is based on one or more tables.
Sometimes you need to create a temporary table (eg. to combine or sort data) and you want that data to appear in a report. The problem is that you can't use a temporary table directly in the DataItem-property of the report. It only accepts "real" tables.

The solution for this is to use the virtual table Integer instead, and write code to simulate the OnAfterGetRecord-trigger.

OnPreDataItem()
FOR i := 1 TO 80 DO BEGIN
  tmpItem.INIT;
  tmpItem."No." := FORMAT(i);
  tmpItem.Description := 'Item description ' + FORMAT(i);
  tmpItem."Unit Price" := i * 1000;
  tmpItem.INSERT;
END;

tmpItem.RESET;
SETRANGE(Number,1,tmpItem.COUNT);			
			
OnAfterGetRecord()
IF Number = 1 THEN
  tmpItem.FIND('-')
ELSE
  tmpItem.NEXT;

When defining the layout of your report, you use this Integer-dataitem to place your headers and body's.
You can't use the Field Menu to place fields on your report: you have to type the name of your tmp-variable together with the fieldname (eg. tmpItem.Description).

The result is a normally looking report: