[go: up one dir, main page]

Menu

[r22]: / rpbasereport.pas  Maximize  Restore  History

Download this file

2245 lines (2122 with data), 61.1 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
{*******************************************************}
{ }
{ Report Manager }
{ }
{ The report base component, it contains }
{ subreports, pagesetup, printer selection... }
{ }
{ }
{ Copyright (c) 1994-2002 Toni Martir }
{ toni@pala.com }
{ }
{ This file is under the MPL license }
{ If you enhace this file you must provide }
{ source code }
{ }
{ }
{*******************************************************}
// One report is composed of subreports, the report has
// page setup properties and a subreport list
// The subreports are printed in order and can have
// diferent datasources, grouping, sections etc
unit rpbasereport;
interface
{$I rpconf.inc}
uses Classes,sysutils,rptypes,rpsubreport,rpsection,rpmdconsts,
rpdatainfo,rpparams,rpeval,rptypeval,rpprintitem,rpmdbarcode,
rpmetafile,
{$IFDEF USEVARIANTS}
types,dateutils,Variants,
{$ENDIF}
rpalias,db,
{$IFDEF USEZLIB}
{$IFDEF DELPHI2009UP}
zlib,
{$ENDIF}
{$IFNDEF DELPHI2009UP}
rpmzlib,
{$ENDIF}
{$ENDIF}
{$IFDEF USERPDATASET}
rpdataset,
{$ENDIF}
{$IFDEF LINUX}
Libc,
{$ENDIF}
{$IFDEF MSWINDOWS}
mmsystem,windows,
{$ENDIF}
rpmunits;
const
MILIS_PROGRESS_DEFAULT=500;
// 1 cms=574
// 0.5 cms=287
CONS_DEFAULT_GRIDWIDTH=115;
CONS_DEFAULT_GRIDCOLOR=$FF0000;
CONS_MIN_GRID_WIDTH=10;
// 29,7/2.54*1440
DEFAULT_PAGEHEIGHT=16837;
DEFAULT_PAGEWIDTH=11906;
// default Margins
// Left 1 cm, Right 1 cm, Top 1 cm Bottom 1.5 cm
DEFAULT_LEFTMARGIN=574;
DEFAULT_RIGHTMARGIN=574;
DEFAULT_BOTTOMMARGIN=861;
DEFAULT_TOPMARGIN=574;
// Minimum grid
type
TRpBaseReport=class;
TRpSubReportListItem=class;
TRpProgressEvent=procedure (Sender:TRpBaseReport;var docancel:boolean) of object;
TRpSubReportList=class(TCollection)
private
FReport:TRpBaseReport;
function GetItem(Index:Integer):TRpSubReportListItem;
procedure SetItem(index:integer;Value:TRpSubReportListItem);
public
constructor Create(rp:TRpBaseReport);
function Add:TRpSubReportListItem;
function IndexOf(Value:TRpSubReport):integer;
property Items[index:integer]:TRpSubReportListItem read GetItem write SetItem;default;
end;
TRpSubReportListItem=class(TCollectionItem)
private
FSubReport:TRpSubReport;
procedure SetSubReport(Value:TRpSubReport);
public
procedure Assign(Source:TPersistent);override;
published
property SubReport:TRpSubReport read FSubReport write SetSubReport;
end;
TIdenReportVar=class(TIdenFunction)
private
FReport:TRpBaseReport;
protected
function GetRpValue:TRpValue;override;
public
varname:string;
end;
TIdenEOF=class(TIdenFunction)
private
FReport:TRpBaseReport;
protected
function GetRpValue:TRpValue;override;
public
constructor Create(AOwner:TComponent);override;
end;
TThreadExecReport=class;
TRpBaseReport=class(TComponent)
private
FSubReports:TRpSubReportList;
FPageOrientation:TRpOrientation;
FPagesize:TRpPagesize;
FPageSizeQt:integer;
FPageWidth:TRpTwips;
FPageHeight:TRpTwips;
FCustomPageWidth:TRpTwips;
FCustomPageHeight:TRpTwips;
FPageBackColor:TRpColor;
FPreviewStyle:TRpPreviewStyle;
FPreviewWindow:TRpPreviewWindowStyle;
FPreviewMargins:Boolean;
FOnReadError:TReaderError;
FDataInfo:TRpDataInfoList;
FDatabaseInfo:TRpDatabaseInfoList;
FParams:TRpParamList;
FGridVisible:Boolean;
FGridEnabled:Boolean;
FGridColor:integer;
FGridLines:Boolean;
FGridWidth:integer;
FGridHeight:integer;
FLanguage:integer;
FMetafile:TRpMetafileReport;
FOnProgress:TRpProgressEvent;
FLeftMargin,FTopMargin,FRightMargin,FBottomMargin:TRpTwips;
FCopies:integer;
FCollateCopies:boolean;
FTwoPass:boolean;
FMilisProgres:integer;
FPrinterFonts:TRpPrinterFontsOption;
difmilis:int64;
FPrinterSelect:TRpPrinterSelect;
FPrintOnlyIfDataAvailable:Boolean;
FStreamFormat:TRpStreamFormat;
FReportAction:TRpReportActions;
FPreviewAbout:Boolean;
// Default font properties
FWFontName:widestring;
FLFontName:widestring;
FFontSize:smallint;
FFontRotation:smallint;
FFontStyle:integer;
FFontColor:integer;
FBackColor:integer;
FTransparent:Boolean;
FCutText:Boolean;
FWordWrap:Boolean;
FAlignMent:integer;
FVAlignMent:integer;
FSingleLine:boolean;
FType1Font:TRpType1Font;
FBidiModes:TStrings;
FMultiPage:Boolean;
FPrintStep:TRpSelectFontStep;
FPaperSource:Integer;
FDuplex:Integer;
FForcePaperName:String;
FLinesPerInch:Word;
fintpageindex:integer;
FOnWorkAsyncError:TWorkAsyncError;
FOnWorkProgress:TMetaFileWorkProgress;
procedure FInternalOnReadError(Reader: TReader; const Message: string;
var Handled: Boolean);
procedure SetSubReports(Value:TRpSubReportList);
procedure SetDataInfo(Value:TRpDataInfoList);
procedure SetDatabaseInfo(Value:TRpDatabaseInfoList);
procedure SetParams(Value:TRpParamList);
procedure SetGridWidth(Value:TRpTwips);
procedure SetGridHeight(Value:TRpTwips);
procedure ReadWFontName(Reader:TReader);
procedure WriteWFontName(Writer:TWriter);
procedure ReadLFontName(Reader:TReader);
procedure WriteLFontName(Writer:TWriter);
procedure SetBidiModes(Value:TStrings);
function Newlanguage(alanguage:integer):integer;
procedure StopWork;
protected
oldprintedsectionext:TPoint;
oldprintedsection:TRpSection;
printingonepass:boolean;
AbortingThread:Boolean;
FThreadExec:TThreadExecReport;
FExecuting:Boolean;
FUpdatePageSize:Boolean;
currentorientation:TRpOrientation;
lasterrorprocessing:WideString;
FTotalPagesList:TList;
FEvaluator:TRpEvaluator;
FIdentifiers:TStringList;
FAliasList:TRpAlias;
FCompose:Boolean;
FPendingSections:TStringList;
section:TRpSection;
subreport:TRpSubreport;
FRecordCount:integer;
FDriver:TRpPrintDriver;
// Identifiers
Fidenpagenum:TIdenReportVar;
Fidenlanguage:TIdenReportVar;
Fidenpagenumgroup:TIdenReportVar;
FidenEof:TIdenEof;
Fidenfreespace:TIdenReportVar;
Fidenpagewidth:TIdenReportVar;
Fidenpageheight:TIdenReportVar;
Fidenfreespacecms:TIdenReportVar;
Fidenfreespaceinch:TIdenReportVar;
Fidencurrentgroup:TIdenReportVar;
FIdenfirstsection:TIdenReportVar;
// Other
FInternalPageWidth:TRpTwips;
FInternalPageHeight:TRpTwips;
FDataAlias:TRpAlias;
pageposy,pageposx:integer;
freespace:integer;
printedsomething:Boolean;
gheaders,gfooters:TList;
FGroupHeaders:TStringList;
{$IFDEF MSWINDOWS}
mmfirst,mmlast:DWORD;
{$ENDIF}
{$IFDEF LINUX}
milifirst,mililast:TDatetime;
{$ENDIF}
rPageSizeQt:TPageSizeQt;
procedure GetChildren(Proc: TGetChildProc; Root: TComponent);override;
procedure UpdateCachedSources(alias:string);
procedure CheckProgress(finished:Boolean);
procedure FillGlobalHeaders;
procedure ClearTotalPagesList;
function OnGraphicOp(Top,Left,Width,Height:integer;
DrawStyle:integer;BrushStyle:integer;BrushColor:integer;
PenStyle:integer;PenWidth:integer; PenColor:integer):Boolean;
function OnPageOp(indexqt:integer;custom:Boolean;
customwidth,customheight,papersource:integer;
ForcePaperName:String;duplex:integer):Boolean;
function OnOrienationOp(orientation:integer):Boolean;
function OnImageOp(Top,Left,Width,Height:integer;
DrawStyle,DPIRes:integer;PreviewOnly:Boolean;Image:WideString):Boolean;
function OnBarcodeOp (Top,Left,Width,Height:integer;
Expression,DisplayFormat:WideString;BarType,Modul:Integer;Ratio,Rotation:Currency;
CalcChecksum:Boolean;BrushColor:Integer):Boolean;
function OnTextOp(Top,Left,Width,Height:integer;
Text,LFontName,WFontName:WideString;
FontSize,FontRotation,FontStyle,FontColor,Type1Font:integer;
CutText:boolean;Alignment:integer;WordWrap,RightToLeft:Boolean;
PrintStep,BackColor:integer;transparent:boolean):Boolean;
function OnTextheight(Text,LFontName,WFontName:WideString;
RectWidth,FontSize,FontStyle,Type1Font:integer;
PrintStep:integer):integer;
function ReOpenOp(datasetname:String;sql:Widestring):BOolean;
function OnParamInfo(ParamName:String;index:integer):String;
procedure CheckIfDataAvailable;
procedure UpdateParamsBeforeOpen(index:integer;doeval:boolean);
procedure DefineProperties(Filer:TFiler);override;
procedure DoPrintInternal;
property OnWorkProgress:TMetaFileWorkProgress read FOnWorkProgress write
FOnWorkProgress;
public
Errorprocessing:Boolean;
FailIfLoadExternalError:Boolean;
printing:boolean;
CurrentSubReportIndex:integer;
CurrentSectionIndex:integer;
PageNum:integer;
PageNumGroup:integer;
LastPage:Boolean;
ProgressToStdOut:Boolean;
AdoNetDriver:integer;
AsyncExecution:boolean;
maximum_width:integer;
maximum_height:integer;
procedure LoadExternals;virtual;
procedure AddReportItemsToEvaluator(eval:TRpEvaluator);
procedure InitEvaluator;
procedure BeginPrint(Driver:TRpPrintDriver);virtual;abstract;
procedure EndPrint;virtual;abstract;
function PrintNextPage:boolean;virtual;abstract;
procedure PrintAll(Driver:TRpPrintDriver);
property RecordCount:integer read FRecordCount;
property Metafile:TRpMetafileReport read FMetafile;
property Identifiers:TStringList read FIdentifiers;
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
procedure FreeSubreports;
function AddSubReport:TRpSubReport;
procedure DeleteSubReport(subr:TRpSubReport);
// Streaming functions and properties
procedure SaveToStream(Stream:TStream);
procedure SaveToFile(Filename:string);
procedure LoadFromStream(Stream:TStream);
procedure LoadFromFile(FileName:string);
property OnReadError:TReaderError read FOnReadError write FOnReadError;
// Design functions
procedure Createnew;
// Print functions
procedure ActivateDatasets;
procedure DeActivateDatasets;
procedure AddTotalPagesItem(apageindex,aobjectindex:integer;
adisplayformat:widestring);
function IsDotNet:boolean;
property OnWorkAsyncError:TWorkAsyncError read FOnWorkAsyncError write FOnWorkAsyncError;
property Evaluator:TRpEvaluator read FEvaluator;
procedure Compose(PrevReport:TRpBaseReport;execute:Boolean;ADriver:TRpPrintDriver);
property OnProgress:TRpProgressEvent read FOnProgress write FOnProgress;
property AliasList:TRpAlias read FAliasList write FAliasList;
property idenpagenum:TIdenReportVar read fidenpagenum;
property idenlanguage:TIdenReportVar read fidenlanguage;
property ideneof:TIdenEof read fideneof;
property idenfreespace:TIdenReportVar read fidenfreespace;
property idenfreespacecms:TIdenReportVar read fidenfreespacecms;
property idenfreespaceinch:TIdenReportVar read fidenfreespaceinch;
property idencurrentgroup:TIdenReportVar read fidencurrentgroup;
property MilisProgres:integer read FMilisProgres write FMilisProgres
default MILIS_PROGRESS_DEFAULT;
procedure AlignSectionsTo(linesperinch:integer);
procedure SetLanguage(index:integer);
procedure PrepareParamsBeforeOpen;
procedure AssignDefaultFontTo(aitem:TRpGenTextComponent);
procedure GetDefaultFontFrom(aitem:TRpGenTextComponent);
function GetSQLValue(connectionname,sql:String):Variant;
function RequestPage(pageindex:integer):boolean;
function CheckParameters(paramlist:TRpParamList;var paramname,amessage:string):Boolean;
// Default Font properties
property WFontName:widestring read FWFontName write FWFontName;
property LFontName:widestring read FLFontName write FLFontName;
published
property GridVisible:Boolean read FGridVisible write FGridVisible default true;
property GridLines:Boolean read FGridLines write FGridLines default false;
property GridEnabled:Boolean read FGridEnabled write FGridEnabled default true;
property GridColor:integer read FGridColor write FGridColor default CONS_DEFAULT_GRIDCOLOR;
property GridWidth:TRpTwips read FGridWidth write SetGridWidth default CONS_DEFAULT_GRIDWIDTH;
property GridHeight:TRpTwips read FGridHeight write SetGridHeight default CONS_DEFAULT_GRIDWIDTH;
// PageSetup properties
property PageOrientation:TRpOrientation read FPageOrientation
write FPageOrientation default rpOrientationDefault;
property Pagesize:TRpPageSize read FPagesize write FPageSize
default rpPageSizeDefault;
property PagesizeQt:integer read FPagesizeQt write FPageSizeQt
default 0;
property PageHeight:TRpTwips read FPageHeight write FPageHeight
default DEFAULT_PAGEHEIGHT;
property PageWidth:TRpTwips read FPageWidth write FPageWidth
default DEFAULT_PAGEWIDTH;
property CustomPageHeight:TRpTwips read FCustomPageHeight write FCustomPageHeight
default DEFAULT_PAGEHEIGHT;
property CustomPageWidth:TRpTwips read FCustomPageWidth write FCustomPageWidth
default DEFAULT_PAGEWIDTH;
property PageBackColor:TRpColor read FPageBackColor write FPageBackColor;
property PreviewStyle:TRpPreviewStyle read FPreviewStyle
write FPreviewStyle default spWide;
property PreviewMargins:Boolean read FPreviewMargins
write FPreviewMargins default false;
property PreviewWindow:TRpPreviewWindowStyle read FPreviewWindow
write FPreviewWindow default spwNormal;
property LeftMargin:TRpTwips read FLeftMargin write FLeftMargin
default DEFAULT_LEFTMARGIN;
property TopMargin:TRpTwips read FTopMargin write FTopMargin
default DEFAULT_TOPMARGIN;
property RightMargin:TRpTwips read FRightMargin write FRightMargin
default DEFAULT_RIGHTMARGIN;
property BottomMargin:TRpTwips read FBottomMargin write FBottomMargin
default DEFAULT_BOTTOMMARGIN;
property PrinterSelect:TRpPrinterSelect read FPrinterSelect write FPrinterSelect
default pRpDefaultPrinter;
// Subreports
property SubReports:TRpSubReportList read FSubReports write SetSubReports;
property DataInfo:TRpDataInfoList read FDataInfo write SetDataInfo;
property DatabaseInfo:TRpDatabaseInfoList read FDatabaseInfo write SetDatabaseInfo;
property Params:TRpParamList read FParams write SetParams;
// Language
property Language:integer read FLanguage write SetLanguage default -1;
// Other
property Copies:integer read FCopies write FCopies default 1;
property CollateCopies:boolean read FCollateCopies write FCollateCopies default false;
property TwoPass:boolean read FTwoPass write FTwoPass default false;
property PrinterFonts:TRpPrinterFontsOption read FPrinterFonts
write FPrinterFonts default rppfontsdefault;
property PrintOnlyIfDataAvailable:Boolean read FPrintOnlyIfDataAvailable
write FPrintOnlyIfDataAvailable default false;
property StreamFormat:TRpStreamFormat read FStreamFormat
write FStreamFormat;
property ReportAction:TRpReportActions read FReportAction write FReportAction;
property PreviewAbout:Boolean read FPreviewAbout write FPreviewAbout
default true;
// Default font props
property Type1Font:TRpType1Font read FType1Font write FType1Font;
property FontSize:smallint read FFontSize write FFontSize default 10;
property FontRotation:smallint read FFontRotation write FFontRotation default 0;
property FontStyle:integer read FFontStyle write FFontStyle default 0;
property FontColor:integer read FFontColor write FFontColor default 0;
property BackColor:integer read FBackColor write FBackColor default $FFFFFF;
property Transparent:Boolean read FTransparent write FTransparent default true;
property CutText:Boolean read FCutText write FCutText default false;
property Alignment:integer read FAlignment write FAlignment default 0;
property VAlignment:integer read FVAlignment write FVAlignment default 0;
property WordWrap:Boolean read FWordWrap write FWordWrap default false;
property SingleLine:boolean read FSingleLine write FSingleLine default false;
property BidiModes:TStrings read FBidiModes write SetBidiModes;
property MultiPage:Boolean read FMultiPage write FMultiPage default false;
property PrintStep:TRpSelectFontStep read FPrintStep write FPrintStep
default rpselectsize;
// Paper source
property PaperSource:Integer read FPaperSource write FPaperSource default 0;
property Duplex:Integer read FDuplex write FDuplex default 0;
property ForcePaperName:String read FForcePaperName write FForcePaperName;
// Interline
property LinesPerInch:Word read FLinesPerInch write FLinesPerInch default 600;
end;
TThreadExecReport=class(TThread)
public
report:TRpBaseReport;
docancel:boolean;
procedure Execute;override;
procedure DoProgress;
end;
implementation
uses rpxmlstream,rplabelitem,rpmdchart;
function TIdenReportVar.GeTRpValue:TRpValue;
var
subrep:TRpSubReport;
begin
Result:=Null;
if ((varname='PAGE') or (varname='PAGINA')) then
Result:=freport.PageNum+1
else
if ((varname='PAGENUM') or (varname='NUMPAGINA')) then
Result:=freport.PageNumGroup+1
else
if varname='FREE_SPACE_TWIPS' then
Result:=freport.freespace
else
if varname='FREE_SPACE_CMS' then
Result:=twipstocms(freport.freespace)
else
if varname='FREE_SPACE_INCH' then
Result:=twipstoinchess(freport.freespace)
else
if varname='CURRENTGROUP' then
begin
if freport.CurrentSubreportIndex>=freport.Subreports.Count then
subrep:=freport.Subreports.Items[freport.CurrentSubreportIndex-1].SubReport
else
subrep:=freport.Subreports.Items[freport.CurrentSubreportIndex].SubReport;
if subrep.LastRecord then
Result:=subrep.GroupCount
else
Result:=subrep.CurrentGroupIndex;
end
else
if varname='FIRSTSECTION' then
begin
Result:=not freport.printedsomething;
end
else
if varname='PAGEWIDTH' then
begin
Result:=freport.FInternalPageWidth;
end
else
if varname='PAGEHEIGHT' then
begin
Result:=freport.FInternalPageHeight;
end
else
if varname='LANGUAGE' then
begin
Result:=freport.FLanguage;
end;
end;
// Constructors and destructors
constructor TRpBaseReport.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FLinesPerInch:=600;
FPaperSource:=0;
FDuplex:=0;
FPreviewMargins:=false;
FGroupHeaders:=TStringList.Create;
FPreviewAbout:=true;
FStreamFormat:=rpStreamtext;
gheaders:=TList.Create;
gfooters:=TList.Create;
FailIfLoadExternalError:=True;
FMilisProgres:=MILIS_PROGRESS_DEFAULT;
FLanguage:=-1;
FCopies:=1;
FPageOrientation:=rpOrientationDefault;
// Means default pagesize
FPagesize:=rpPageSizeDefault;
FLeftMargin:=DEFAULT_LEFTMARGIN;
FRightMargin:=DEFAULT_RIGHTMARGIN;
FBottomMargin:=DEFAULT_BOTTOMMARGIN;
FTopMargin:=DEFAULT_TOPMARGIN;
// Means white
FPageBackColor:=$FFFFFF;
FPageWidth:=DEFAULT_PAGEWIDTH;
FPageheight:=DEFAULT_PAGEHEIGHT;
FCustomPageWidth:=DEFAULT_PAGEWIDTH;
FCustomPageheight:=DEFAULT_PAGEHEIGHT;
FPreviewStyle:=spWide;
// Def values of grid
FGridVisible:=True;
FGridEnabled:=True;
FGridColor:=CONS_DEFAULT_GRIDCOLOR;
FGridLines:=False;
FGridWidth:=CONS_DEFAULT_GRIDWIDTH;
FGridHeight:=CONS_DEFAULT_GRIDWIDTH;
FPendingSections:=TStringList.Create;
// Subreports
FSubReports:=TRpSubReportList.Create(Self);
// Data Info
FDataInfo:=TRpDataInfoList.Create(Self);
FDatabaseInfo:=TRpDatabaseInfoList.Create(Self);
FParams:=TRpParamList.Create(Self);
// Identifiers
FIdentifiers:=TStringList.Create;
FIdentifiers.Sorted:=true;
FIdentifiers.Duplicates:=dupError;
// Pagenum
FIdenPagenum:=TIdenReportVar.Create(nil);
Fidenpagenum.FReport:=self;
FidenPagenum.varname:='PAGE';
FIdenLanguage:=TIdenReportVar.Create(nil);
FIdenLanguage.FReport:=self;
FIdenLanguage.varname:='LANGUAGE';
FIdenPagenumgroup:=TIdenReportVar.Create(nil);
Fidenpagenumgroup.FReport:=self;
FidenPagenumgroup.varname:='PAGENUM';
FIdenfreespace:=TIdenReportVar.Create(nil);
Fidenfreespace.varname:='FREE_SPACE_TWIPS';
Fidenfreespace.FReport:=self;
FIdenpagewidth:=TIdenReportVar.Create(nil);
Fidenpagewidth.varname:='PAGEWIDTH';
Fidenpagewidth.FReport:=self;
FIdenpageheight:=TIdenReportVar.Create(nil);
Fidenpageheight.varname:='PAGEHEIGHT';
Fidenpageheight.FReport:=self;
FIdenfreespacecms:=TIdenReportVar.Create(nil);
Fidenfreespacecms.varname:='FREE_SPACE_CMS';
Fidenfreespacecms.FReport:=self;
FIdenfreespaceinch:=TIdenReportVar.Create(nil);
Fidenfreespaceinch.varname:='FREE_SPACE_INCH';
Fidenfreespaceinch.FReport:=self;
FIdencurrentgroup:=TIdenReportVar.Create(nil);
Fidencurrentgroup.varname:='CURRENTGROUP';
Fidencurrentgroup.FReport:=self;
FIdenfirstsection:=TIdenReportVar.Create(nil);
Fidenfirstsection.varname:='FIRSTSECTION';
FidenFirstSection.FReport:=self;
FIdeneof:=TIdenEOF.Create(nil);
Fideneof.FReport:=self;
// Metafile
FMetafile:=TRpMetafileReport.Create(nil);
metafile.OnRequestPage:=RequestPage;
FOnWorkProgress:=metafile.WorkProgress;
OnWorkAsyncError:=metafile.WorkAsyncError;
metafile.OnStopWork:=StopWork;
FDataAlias:=TRpAlias.Create(nil);
FTotalPagesList:=TList.Create;
// Other
FPrinterFonts:=rppfontsdefault;
FReportAction:=[];
// Default font
FLFontName:='Helvetica';
FWFontName:='Arial';
FontSize:=10;
FontRotation:=0;
FontStyle:=0;
FontColor:=0;
FBackColor:=$FFFFFF;
FTransparent:=true;
FCutText:=false;
FBidiModes:=TStringList.Create;
//
InitEvaluator;
end;
procedure TRpBaseReport.FillGlobalHeaders;
var
subrep:TRpSubReport;
i,j:integer;
k:integer;
begin
gheaders.clear;
gfooters.clear;
for i:=0 to Subreports.Count-1 do
begin
subrep:=SubReports.Items[i].SubReport;
j:=subrep.FirstPageHeader;
for k:=0 to subrep.PageHeaderCount-1 do
begin
if subrep.Sections[j+k].Section.Global then
gheaders.Add(subrep.Sections[j+k].Section);
end;
j:=subrep.FirstPageFooter;
for k:=0 to subrep.PageFooterCount-1 do
begin
if subrep.Sections[j+k].Section.Global then
gfooters.Add(subrep.Sections[j+k].Section);
end;
end;
end;
procedure TRpBaseReport.SetGridWidth(Value:TRpTwips);
begin
if Value<CONS_MIN_GRID_WIDTH then
Value:=CONS_MIN_GRID_WIDTH;
FGridWidth:=Value;
end;
procedure TRpBaseReport.SetGridHeight(Value:TRpTwips);
begin
if Value<CONS_MIN_GRID_WIDTH then
Value:=CONS_MIN_GRID_WIDTH;
FGridHeight:=Value;
end;
procedure TRpBaseReport.AddTotalPagesItem(apageindex,aobjectindex:integer;
adisplayformat:widestring);
var
aobject:TTotalPagesObject;
begin
aobject:=TTotalPagesObject.Create;
FTotalPagesList.Add(aobject);
aobject.PageIndex:=apageindex;
aobject.ObjectIndex:=aobjectindex;
aobject.DisplayFormat:=adisplayformat;
end;
procedure TRpBaseReport.ClearTotalPagesList;
var
i:integer;
begin
for i:=0 to FTotalPagesList.Count-1 do
begin
TObject(FTotalPagesList.Items[i]).Free;
end;
FTotalPagesList.Clear;
end;
destructor TRpBaseReport.Destroy;
begin
if (FExecuting) then
begin
AbortingThread:=false;
{$IFDEF MSWINDOWS}
WaitForSingleObject(FThreadExec.Handle,INFINITE);
{$ENDIF}
{$IFDEF LINUX}
FThreadExec.WaitFor;
{$ENDIF}
end;
FGroupHeaders.free;
gheaders.free;
gfooters.free;
FPendingSections.Free;
FSubReports.free;
FDataInfo.free;
FDatabaseInfo.free;
FParams.free;
FIdentifiers.free;
FMetafile.Free;
FDataAlias.Free;
FIdenPagenum.free;
FIdenPagenumgroup.free;
Fidenfreespace.free;
FIdenPagewidth.free;
FIdenPageHeight.free;
FIdenCurrentGroup.free;
FIdenFirstSection.free;
Fidenfreespacecms.free;
FBidiModes.free;
Fidenfreespaceinch.free;
FIdenLanguage.free;
FIdenEof.free;
ClearTotalPagesList;
FTotalPagesList.free;
if Assigned(FEvaluator) then
begin
FEvaluator.free;
FEvaluator:=nil;
end;
inherited destroy;
end;
// Streaming procedures
// GetChildren helps streaming the subreports
procedure TRpBaseReport.GetChildren(Proc: TGetChildProc; Root: TComponent);
var
I: Integer;
OwnedComponent: TComponent;
// rpsubreport:TRpSubReport;
begin
inherited GetChildren(Proc, Root);
if Root = Self then
for I := 0 to ComponentCount - 1 do
begin
OwnedComponent := Components[I];
if not OwnedComponent.HasParent then
Proc(OwnedComponent);
// if OwnedComponent is TRpSubReport then
// begin
// if subreport.
// Proc(OwnedComponent);
// end;
end;
end;
procedure TRpBaseReport.SaveToStream(Stream:TStream);
var
{$IFDEF USEZLIB}
zstream:TCompressionStream;
{$ENDIF}
theformat:TRpStreamFormat;
memstream:TMemoryStream;
forcexml:boolean;
i:integer;
begin
// restore parameters initial values
Params.RestoreInitialValues;
theformat:=FStreamFormat;
forcexml:=false;
for i:=0 to DatabaseInfo.Count-1 do
begin
if DatabaseInfo.Items[i].Driver in [rpdatadriver,rpdotnet2driver] then
begin
forcexml:=true;
break;
end;
end;
if (forcexml) then
if ((theformat<>rpStreamXML) AND (theformat<>rpStreamXMLZLib)) then
theformat:=rpStreamXML;
if (Subreports.Count<1) then
begin
AddSubReport;
end;
{$IFNDEF USEZLIB}
if theformat=rpStreamZLib then
theformat:=rpStreambinary;
{$ENDIF}
{$IFDEF USEZLIB}
if theformat=rpStreamZLib then
begin
zstream:=TCompressionStream.Create(clDefault,Stream);
try
zstream.WriteComponent(Self);
finally
zstream.free;
end;
end
else
if theformat=rpStreamXMLZLib then
begin
zstream:=TCompressionStream.Create(clDefault,Stream);
try
memstream:=TMemorystream.Create;
try
WriteReportXML(Self,memstream);
memstream.Seek(0,soFromBeginning);
zstream.CopyFrom(memstream,memstream.size);
finally
memstream.free;
end;
finally
zstream.free;
end;
end
else
{$ENDIF}
if theformat=rpStreamBinary then
begin
Stream.WriteComponent(Self);
end
else
if theformat=rpStreamXML then
begin
WriteReportXML(Self,Stream);
end
else
begin
memstream:=TMemoryStream.Create;
try
memstream.WriteComponent(Self);
memstream.Seek(0,soFromBeginning);
ObjectBinaryToText(memstream,Stream);
finally
memstream.free;
end;
end;
end;
procedure TRpBaseReport.FreeSubreports;
var
i:integer;
begin
// If it's destroying left do the work
if (csDestroying in ComponentState) then
exit;
// Frees all the reports
for i:=0 to FSubreports.Count-1 do
begin
FSubReports.Items[i].FSubReport.Free;
end;
FSubReports.Clear;
end;
function TRpBaseReport.AddSubReport:TRpSubReport;
var
it:TRpSubReportListItem;
begin
it:=SubReports.Add;
it.FSubReport:=TRpSubreport.Create(Self);
Generatenewname(it.FSubReport);
it.FSubReport.CreateNew;
Result:=it.FSubReport;
end;
procedure TRpBaseReport.CreateNew;
begin
// Creates a new default report
FreeSubreports;
AddSubReport;
end;
procedure TRpBaseReport.SaveToFile(Filename:string);
var
fstream:TFileStream;
begin
fstream:=TFileStream.Create(Filename,fmCreate);
try
SaveToStream(fstream);
finally
fstream.free;
end;
end;
procedure TRpBaseReport.LoadFromFile(FileName:string);
var
stream:TFileStream;
begin
stream:=TFileStream.Create(Filename,fmOpenRead or fmShareDenyWrite);
try
LoadFromStream(stream);
finally
stream.free;
end;
end;
procedure TRpBaseReport.LoadFromStream(Stream:TStream);
var
reader:TReader;
memstream,amemstream:TMemoryStream;
readed:integer;
buf:array of Byte;
{$IFDEF USEZLIB}
zlibs:TDeCompressionStream;
{$ENDIF}
theformat:TRpStreamFormat;
firstchar:char;
first:boolean;
begin
// FreeSubrepots
FreeSubreports;
MemStream:=TMemoryStream.Create;
try
firstchar:=chr(0);
first:=false;
// Copy to memory stream
SetLength(buf,120000);
repeat
{$IFDEF DOTNETD}
readed:=Stream.Read(buf,120000);
memstream.Write(buf,readed);
{$ENDIF}
{$IFNDEF DOTNETD}
readed:=Stream.Read(buf[0],120000);
memstream.Write(buf[0],readed);
{$ENDIF}
if ((readed>0) and (not first)) then
begin
first:=true;
firstchar:=char(buf[0]);
end;
until readed<120000;
memstream.Seek(0,soFrombeginning);
// Looks stream type
if (memstream.size<1) then
Raise Exception.Create(SRpStreamFormat);
if firstchar='x' then
theformat:=rpStreamzlib
else
if firstchar='o' then
theformat:=rpStreamText
else
if firstchar='<' then
theformat:=rpStreamXML
else
theformat:=rpStreambinary;
{$IFNDEF USEZLIB}
if theformat=rpStreamzlib then
Raise Exception.Create(SRpZLibNotSupported);
{$ENDIF}
{$IFDEF USEZLIB}
if theformat=rpStreamzlib then
begin
amemstream:=TMemoryStream.Create;
try
zlibs:=TDeCompressionStream.Create(MemStream);
try
// Decompress
repeat
readed:=zlibs.Read(buf[0],120000);
amemstream.Write(buf[0],readed);
until readed<120000;
amemstream.Seek(0,soFromBeginning);
// Check if is xml
if PAnsiChar(amemstream.memory)^='<' then
begin
ReadReportXML(self,amemstream);
end
else
begin
reader:=TReader.Create(amemstream,1000);
try
reader.OnError:=FInternalOnReadError;
reader.ReadRootComponent(Self);
finally
reader.free;
end;
end;
finally
zlibs.Free;
end;
finally
amemstream.free;
end;
end
else
{$ENDIF}
if theformat=rpStreambinary then
begin
reader:=TReader.Create(memstream,1000);
try
reader.OnError:=FInternalOnReadError;
reader.ReadRootComponent(Self);
finally
reader.free;
end;
end
else
if theformat=rpStreamXML then
begin
ReadReportXML(self,memstream);
end
else
begin
amemstream:=TMemoryStream.Create;
try
ObjectTextToBinary(memstream,amemstream);
amemstream.Seek(0,soFromBeginning);
reader:=TReader.Create(amemstream,1000);
try
reader.OnError:=FInternalOnReadError;
reader.ReadRootComponent(Self);
finally
reader.free;
end;
finally
amemstream.free;
end;
end;
finally
MemStream.free;
end;
end;
procedure TRpBaseReport.FInternalOnReadError(Reader: TReader; const Message: string;
var Handled: Boolean);
begin
Handled:=false;
// if Pos('AllText',Message)>0 then
// Handled:=True;
if Assigned(FOnReadError) then
reader.OnError:=FOnReadError
end;
procedure TRpBaseReport.SetSubReports(Value:TRpSubReportList);
begin
FSubReports.Assign(Value);
end;
procedure TRpBaseReport.SetDataInfo(Value:TRpDataInfoList);
begin
FDataInfo.Assign(Value);
end;
procedure TRpBaseReport.SetDatabaseInfo(Value:TRpDatabaseInfoList);
begin
FDatabaseInfo.Assign(Value);
end;
// Report collections
constructor TRpSubReportList.Create(rp:TRpBaseReport);
begin
inherited Create(TRpSubReportListItem);
FReport:=rp;
end;
procedure TRpSubReportListItem.SetSubReport(Value:TRpSubReport);
begin
FSubReport:=Value;
Changed(False);
end;
procedure TRpSubReportListItem.Assign(Source:TPersistent);
begin
if Source is TRpSubReportListItem then
begin
FSubReport:=TRpSubReportListItem(Source).FSubReport;
end
else
inherited Assign(Source);
end;
function TRpSubReportList.Add:TRpSubReportListItem;
begin
Result:=TRpSubReportListItem(inherited Add);
end;
function TRpSubReportList.IndexOf(Value:TRpSubReport):integer;
var
i:integer;
begin
Result:=-1;
i:=0;
While i<count do
begin
if items[i].FSubReport=vALUE then
begin
Result:=i;
break;
end;
inc(i);
end;
end;
function TRpSubReportList.GetItem(Index:Integer):TRpSubReportListItem;
begin
Result:=TRpSubReportListItem(inherited GetItem(index));
end;
procedure TRpSubReportList.SetItem(index:integer;Value:TRpSubReportListItem);
begin
inherited SetItem(Index,Value);
end;
procedure TRpBaseReport.DeleteSubReport(subr:TRpSubReport);
var
i:integer;
begin
if FSubReports.Count<2 then
Raise Exception.Create(SRpAtLeastOneSubreport);
i:=0;
while (FSubReports.Items[i].FSubReport<>subr) do
begin
inc(i);
if (i>FSubReports.count-1) then
Raise Exception.Create(SRpSubReportNotFound);
end;
FSubReports.Items[i].FSubReport.FreeSections;
FSubReports.Items[i].FSubReport.Free;
// FSubReports.Delete(i);
FSubReports.Items[i].Free;
end;
procedure TRpBaseReport.SetParams(Value:TRpParamList);
begin
FParams.Assign(Value);
end;
procedure TRpBaseReport.ActivateDatasets;
var
i,index:integer;
alias:string;
dbinfo:TRpDatabaseInfoItem;
dbalias:string;
begin
if FDataInfo.Count<1 then
exit;
try
for i:=0 to FDataInfo.Count-1 do
begin
FDataInfo.Items[i].Cached:=false;
FDataInfo.Items[i].SQLOverride:='';
end;
// The main datasets must be cached
for i:=0 to SubReports.Count-1 do
begin
alias:=SubReports.items[i].Subreport.Alias;
if Length(alias)>0 then
begin
index:=DataInfo.IndexOf(alias);
if index<0 then
Raise Exception.Create(SRpSubreportAliasNotFound+':'+alias);
dbalias:=UpperCase(FDataInfo.Items[index].DatabaseAlias);
index:=DatabaseInfo.IndexOf(dbalias);
if index<0 then
Raise Exception.Create(SRpSubreportAliasNotFound+':'+alias);
dbinfo:=DatabaseInfo.Items[index];
index:=DataInfo.IndexOf(alias);
if (Not (dbinfo.Driver in [rpdataibx,rpdatamybase,rpdatazeos])) then
begin
FDataInfo.Items[index].Cached:=true;
end;
end;
end;
for i:=0 to FDataInfo.Count-1 do
begin
// Watch if external dataset
if Assigned(FAliasList) then
begin
index:=FAliasList.List.indexof(FDataInfo.Items[i].Alias);
if index>=0 then
begin
if Assigned(FAliasList.List.Items[index].dataset) then
begin
FDataInfo.Items[i].Cached:=false;
FDataInfo.Items[i].Dataset:=FAliasList.List.Items[index].dataset;
end;
end;
end;
CheckProgress(false);
end;
for i:=0 to FDataInfo.Count-1 do
begin
if FDataInfo.Items[i].OpenOnStart then
begin
UpdateParamsBeforeOpen(i,true);
FDataInfo.Items[i].Connect(DatabaseInfo,Params);
CheckProgress(false);
end;
end;
except
for i:=0 to FDataInfo.Count-1 do
begin
FDataInfo.Items[i].Disconnect;
end;
Raise;
end;
end;
procedure TRpBaseReport.DeActivateDatasets;
var
i:integer;
begin
for i:=0 to FDataInfo.Count-1 do
begin
FDataInfo.Items[i].DisConnect;
{$IFDEF USERPDATASET}
if Assigned(FDataInfo.Items[i].CachedDataset) then
FDataInfo.Items[i].CachedDataset.DoClose;
{$ENDIF}
end;
for i:=0 to FDatabaseInfo.Count-1 do
begin
FDatabaseInfo.Items[i].DisConnect;
end;
end;
procedure TRpBaseReport.UpdateCachedSources(alias:string);
var
i:integer;
begin
for i:=0 to datainfo.Count-1 do
begin
if datainfo.Items[i].DataSource=alias then
begin
if datainfo.Items[i].Cached then
begin
{$IFDEF USERPDATASET}
// datainfo.Items[i].CachedDataset.DoClose;
datainfo.Items[i].CachedDataset.DoOpen;
{$ENDIF}
end
else
if Not datainfo.Items[i].Dataset.Active then
datainfo.Items[i].Connect(databaseinfo,params);
UpdateCachedSources(datainfo.items[i].alias);
end;
end;
end;
procedure TRpBaseReport.CheckProgress(finished:Boolean);
var
docancel:boolean;
begin
if (Assigned(FOnProgress) or Assigned(metafile.OnWorkProgress)) then
begin
{$IFDEF MSWINDOWS}
mmlast:=TimeGetTime;
difmilis:=(mmlast-mmfirst);
{$ENDIF}
{$IFDEF LINUX}
mililast:=now;
difmilis:=MillisecondsBetween(mililast,milifirst);
{$ENDIF}
if ((difmilis>FMilisProgres) or finished) then
begin
// Get the time
{$IFDEF MSWINDOWS}
mmfirst:=TimeGetTime;
{$ENDIF}
{$IFDEF LINUX}
milifirst:=now;
{$ENDIF}
docancel:=false;
if assigned(FThreadExec) then
begin
if AbortingThread then
docancel:=true;
end
else
begin
if Assigned(FOnProgress) then
FOnProgress(Self,docancel);
if Assigned(metafile.OnWorkProgress) then
begin
metafile.WorkProgress(Self,recordcount,metafile.CurrentPageCount,docancel);
end;
end;
if docancel then
Raise Exception.Create(SRpOperationAborted);
end;
end;
end;
procedure TRpBaseReport.CheckIfDataAvailable;
var
dataavail:boolean;
dinfo:TRpDatainfoItem;
i,index:integer;
begin
if Not FPrintOnlyIfDataAvailable then
exit;
dataavail:=false;
for i:=0 to SubReports.Count-1 do
begin
if Length(SubReports.Items[i].SubReport.Alias)>0 then
begin
index:=datainfo.IndexOf(SubReports.Items[i].SubReport.Alias);
if index>=0 then
begin
dinfo:=datainfo.Items[index];
if dinfo.Dataset.Active then
begin
if Not dinfo.Dataset.Eof then
begin
dataavail:=true;
break;
end;
end;
end;
end;
end;
if not dataavail then
Raise Exception.Create(SRpNoDataAvailableToPrint);
end;
constructor TIdenEOF.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FParamcount:=1;
IdenName:='Eof';
// Help:=SRpInt;
model:='function '+'Eof'+'(alias:string):Boolean';
// aParams:=SRpEof;
end;
function TIdenEof.GeTRpValue:TRpValue;
var
aliasname:string;
index:integer;
dataset:TDataset;
begin
if (not ( (VarType(Params[0])=varString) or (VarType(Params[0])=varOleStr) )) then
Raise TRpNamedException.Create(SRpEvalType,
IdenName);
Result:=true;
aliasname:=String(Params[0]);
index:=FReport.DataInfo.IndexOf(aliasname);
if index<0 then
exit;
{$IFDEF USERPDATASET}
if FReport.DataInfo.Items[index].Cached then
dataset:=FReport.DataInfo.Items[index].CachedDataset
else
{$ENDIF}
dataset:=FReport.DataInfo.Items[index].Dataset;
if Not dataset.Active then
exit;
Result:=dataset.Eof;
end;
procedure TRpBaseReport.Compose(PrevReport:TRpBaseReport;execute:Boolean;ADriver:TRpPrintDriver);
var
i:integer;
aobject:TTotalPagesObject;
begin
if PrevReport.Metafile.CurrentPageCount<1 then
exit;
ClearTotalPagesList;
metafile.Assign(PrevReport.Metafile);
for i:=0 to PrevReport.FTotalPagesList.Count-1 do
begin
aobject:=TTotalPagesObject(PrevReport.FTotalPagesList.Items[i]);
AddTotalPagesItem(aobject.PageIndex,aobject.ObjectIndex,aobject.DisplayFormat);
end;
freespace:=PrevReport.freespace;
pageposy:=PrevReport.pageposy;
// pageposx:=FLeftMargin;
pageposx:=PrevReport.pageposx;
oldprintedsection:=PrevReport.oldprintedsection;
oldprintedsectionext:=PrevReport.oldprintedsectionext;
FCompose:=True;
TwoPass:=true;
if execute then
begin
PrintAll(ADriver);
end;
end;
procedure TRpBaseReport.AlignSectionsTo(linesperinch:integer);
var
subrep:TRpSubreport;
sec:TRpSection;
i,j:integer;
begin
FTopMargin:=Round((TWIPS_PER_INCHESS/(linesperinch/100))*Round(FTopMargin/(TWIPS_PER_INCHESS/(linesperinch/100))));
for i:=0 to SubReports.Count-1 do
begin
subrep:=Subreports.Items[i].Subreport;
for j:=0 to subrep.Sections.Count-1 do
begin
sec:=subrep.Sections.Items[j].Section;
sec.Height:=Round((TWIPS_PER_INCHESS/(linesperinch/100))*Round(sec.Height/(TWIPS_PER_INCHESS/(linesperinch/100))));
end;
end;
end;
function TRpBaseReport.OnPageOp(indexqt:integer;custom:Boolean;
customwidth,customheight,papersource:integer;
ForcePaperName:String;duplex:integer):Boolean;
begin
rpagesizeqt.Indexqt:=indexqt;
rpagesizeqt.Custom:=custom;
rPageSizeQt.CustomHeight:=customheight;
rPageSizeQt.CustomWidth:=customwidth;
rPageSizeQt.papersource:=papersource;
SetForcePaperName(rpagesizeqt,forcepapername);
Result:=true;
FUpdatePageSize:=true;
end;
function TRpBaseReport.OnOrienationOp(orientation:integer):Boolean;
begin
if Not orientation in [0..2] then
begin
Result:=false
end
else
begin
currentorientation:=TRpOrientation(orientation);
Result:=true;
end;
FUpdatePageSize:=true;
end;
function TRpBaseReport.OnGraphicOp(Top,Left,Width,Height:integer;
DrawStyle:integer;BrushStyle:integer;BrushColor:integer;
PenStyle:integer;PenWidth:integer; PenColor:integer):Boolean;
begin
Result:=true;
metafile.Pages[metafile.CurrentPage].NewDrawObject(Top,Left,Width,Height,
DrawStyle,BrushStyle,BrushColor,PenStyle,PenWidth,PenColor);
end;
function TRpBaseReport.OnImageOp(Top,Left,Width,Height:integer;
DrawStyle,DPIRes:integer;PreviewOnly:Boolean;Image:WideString):Boolean;
var
astream:TMemoryStream;
begin
// Search for the image
Result:=false;
astream:=Evaluator.GetStreamFromExpression(image);
if assigned(astream) then
begin
try
Result:=True;
metafile.Pages[metafile.CurrentPage].NewImageObject(Top,Left,Width,Height,0,
DrawStyle,DPIRes,astream,previewonly);
finally
astream.free;
end;
end;
end;
function TRpBaseReport.OnBarcodeOp (Top,Left,Width,Height:integer;
Expression,DisplayFormat:WideString;BarType,Modul:Integer;Ratio,Rotation:Currency;
CalcChecksum:Boolean;BrushColor:Integer):Boolean;
var
barcode:TRpBarcode;
FValue:Variant;
data:string;
begin
Result:=False;
barcode:=TRpBarcode.Create(Self);
try
barcode.Width:=Width;
barcode.Height:=Height;
barcode.Typ:=TRpBarcodeType(BarType);
barcode.Modul:=Modul;
barcode.Ratio:=Ratio;
barcode.Rotation:=Round(Rotation*10);
barcode.Checksum:=CalcChecksum;
FValue:=Evaluator.EvaluateText(Expression);
barcode.CurrentText:=FormatVariant(displayformat,FValue,rpParamUnknown,true);
try
data:=barcode.Calculatebarcode;
except
on E:Exception do
begin
Raise TRpReportException.Create(E.Message+':'+SrpSCalculatingBarcode+' ',barcode,SRpSBarcode);
end;
end;
// Draws Barcode
barcode.PrintHeight:=Height;
barcode.BColor:=BrushColor;
barcode.DoLines(data, Left,Top,metafile); // draw the barcode
Result:=true;
finally
barcode.Free;
end;
end;
function TRpBaseReport.OnTextheight(Text,LFontName,WFontName:WideString;
RectWidth,FontSize,FontStyle,Type1Font:integer;
PrintStep:integer):integer;
var
textr:TRpTextObject;
extent:TPoint;
begin
textr.Text:=Text;
textr.LFontName:=LFontName;
textr.WFontName:=WFontName;
textr.FontSize:=FontSize;
textr.FontRotation:=0;
textr.FontStyle:=FontStyle;
textr.FontColor:=0;;
textr.Type1Font:=Type1Font;
textr.CutText:=false;
textr.Alignment:=0;
textr.WordWrap:=true;
textr.RightToLeft:=false;
textr.PrintStep:=TRpSelectFontStep(PrintStep);
extent.Y:=0;
extent.x:=rectwidth;
FDriver.TextExtent(textr,extent);
Result:=extent.Y;
end;
function TRpBaseReport.OnTextOp(Top,Left,Width,Height:integer;
Text,LFontName,WFontName:WideString;
FontSize,FontRotation,FontStyle,FontColor,Type1Font:integer;
CutText:boolean;Alignment:integer;WordWrap,RightToLeft:Boolean;
PrintStep,BackColor:integer;transparent:boolean):Boolean;
var
textr:TRpTextObject;
begin
Result:=true;
textr.Text:=Text;
textr.LFontName:=LFontName;
textr.WFontName:=WFontName;
textr.FontSize:=FontSize;
textr.FontRotation:=FontRotation;
textr.FontStyle:=FontStyle;
textr.FontColor:=FontColor;
textr.Type1Font:=Type1Font;
textr.CutText:=CutText;
textr.Alignment:=Alignment;
textr.WordWrap:=WordWrap;
textr.RightToLeft:=RightToLeft;
textr.PrintStep:=TRpSelectFontStep(PrintStep);
metafile.Pages[metafile.CurrentPage].NewTextObject(Top,Left,Width,Height,
textr,BackColor,transparent);
end;
// Print all generaties the metafile, it's capable also
// of evaluate the totalpages expression
procedure TRpBaseReport.PrintAll(Driver:TRpPrintDriver);
var
ncopies:integer;
begin
ncopies:=copies;
if ncopies=0 then
ncopies:=1;
BeginPrint(Driver);
try
Driver.NewDocument(metafile,ncopies,CollateCopies);
try
while Not PrintNextPage do;
finally
Driver.EndDocument;
end;
finally
EndPrint;
end;
end;
procedure TRpBaseReport.UpdateParamsBeforeOpen(index:integer;doeval:boolean);
var
i:integer;
paramname:string;
avalue:Variant;
begin
for i:=0 to Params.Count-1 do
begin
if Params.Items[i].Datasets.IndexOf(datainfo.Items[index].Alias)>=0 then
if (params.items[i].ParamType in [rpParamExpreB,rpParamList]) then
begin
paramname:=params.items[i].Name;
try
if Not VarIsNull(params.items[i].Value) then
begin
if doeval then
begin
avalue := params.items[i].Value;
if (VarIsString(avalue)) then
avalue := QuotedStr(avalue);
FEvaluator.EvaluateText(paramname+':=('+String(avalue)+')');
params.items[i].LastValue:=FEvaluator.EvaluateText(paramname);
end
else
begin
params.items[i].LastValue:=FEvaluator.EvaluateText(String(params.items[i].Value));
end;
end;
except
on E:Exception do
begin
{$IFDEF DOTNETD}
Raise Exception.Create(E.Message+SRpParameter+'-'+paramname);
{$ENDIF}
{$IFNDEF DOTNETD}
E.Message:=E.Message+SRpParameter+'-'+paramname;
Raise;
{$ENDIF}
end;
end;
end;
end;
for i:=0 to Params.Count-1 do
begin
if (params.items[i].ParamType in [rpParamSubstE,rpParamSubstList]) then
begin
paramname:=params.items[i].Name;
try
if Not VarIsNull(params.items[i].Value) then
begin
if doeval then
begin
avalue := params.items[i].Value;
if (VarIsString(avalue)) then
avalue := QuotedStr(avalue);
FEvaluator.EvaluateText('M.'+paramname+':=('+String(avalue)+')');
params.items[i].LastValue:=FEvaluator.EvaluateText('M.'+paramname);
end
else
begin
params.items[i].LastValue:=FEvaluator.EvaluateText(String(params.items[i].Value));
end;
end;
except
on E:Exception do
begin
{$IFDEF DOTNETD}
Raise Exception.Create(E.Message+SRpParameter+'-'+paramname);
{$ENDIF}
{$IFNDEF DOTNETD}
E.Message:=E.Message+SRpParameter+'-'+paramname;
Raise;
{$ENDIF}
end;
end;
end;
end;
end;
procedure TRpBaseReport.PrepareParamsBeforeOpen;
var
i:integer;
begin
for i:=0 to DataInfo.Count-1 do
UpdateParamsBeforeOpen(i,false);
end;
procedure TRpBaseReport.InitEvaluator;
begin
if Assigned(FEvaluator) then
begin
FEvaluator.free;
FEvaluator:=nil;
end;
FEvaluator:=TRpEvaluator.Create(nil);
FEvaluator.Language:=Language;
FEvaluator.OnNewLanguage:=Newlanguage;
FEvaluator.OnGraphicOp:=OnGraphicOp;
FEvaluator.OnOrientationOp:=OnOrienationOp;
FEvaluator.OnpageOp:=OnPageOp;
FEvaluator.OnImageOp:=OnImageOp;
FEvaluator.OnBarcodeOp:=OnBarcodeOp;
FEvaluator.OnTextOp:=OnTextOp;
FEvaluator.OnParamInfo:=OnParamInfo;
FEvaluator.OnTextHeight:=OnTextHeight;
FEvaluator.OnReOpenOp:=ReOpenOp;
FEvaluator.OnGetSQLValue:=GetSQLValue;
end;
procedure TRpBaseReport.SetBidiModes(Value:TStrings);
begin
FBidiModes.Assign(Value);
end;
procedure TRpBaseReport.WriteWFontName(Writer:TWriter);
begin
WriteWideString(Writer, FWFontName);
end;
procedure TRpBaseReport.WriteLFontName(Writer:TWriter);
begin
WriteWideString(Writer, FLFontName);
end;
procedure TRpBaseReport.ReadLFontName(Reader:TReader);
begin
FLFontName:=ReadWideString(Reader);
end;
procedure TRpBaseReport.ReadWFontName(Reader:TReader);
begin
FWFontName:=ReadWideString(Reader);
end;
procedure TRpBaseReport.DefineProperties(Filer:TFiler);
begin
inherited;
Filer.DefineProperty('WFontName',ReadWFontName,WriteWFontName,True);
Filer.DefineProperty('LFontName',ReadLFontName,WriteLFontName,True);
end;
procedure TRpBaseReport.AssignDefaultFontTo(aitem:TRpGenTextComponent);
begin
aitem.Type1Font:=Type1Font;
aitem.FontSize:=FontSize;
aitem.FontStyle:=FontStyle;
aitem.FontRotation:=FontRotation;
aitem.FontColor:=FontColor;
aitem.BackColor:=BackColor;
aitem.Transparent:=Transparent;
aitem.CutText:=CutText;
aitem.Alignment:=Alignment;
aitem.VAlignment:=VAlignment;
aitem.Wordwrap:=Wordwrap;
aitem.SingleLine:=SingleLine;
aitem.BidiModes:=BidiModes;
aitem.Multipage:=Multipage;
aitem.PrintStep:=PrintStep;
aitem.LFontName:=LFontName;
aitem.WFontName:=WFontName;
end;
procedure TRpBaseReport.GetDefaultFontFrom(aitem:TRpGenTextComponent);
begin
Type1Font:=aitem.Type1Font;
FontSize:=aitem.FontSize;
FontStyle:=aitem.FontStyle;
FontRotation:=aitem.FontRotation;
FontColor:=aitem.FontColor;
BackColor:=aitem.BackColor;
Transparent:=aitem.Transparent;
CutText:=aitem.CutText;
Alignment:=aitem.Alignment;
VAlignment:=aitem.VAlignment;
Wordwrap:=aitem.Wordwrap;
SingleLine:=aitem.SingleLine;
BidiModes:=aitem.BidiModes;
Multipage:=aitem.Multipage;
PrintStep:=aitem.PrintStep;
LFontName:=aitem.LFontName;
WFontName:=aitem.WFontName;
end;
function TRpBaseReport.GetSQLValue(connectionname,sql:String):Variant;
var
adataset:TDataset;
begin
Result:=Null;
adataset:=databaseinfo.ItemByName(connectionname).OpenDatasetFromSQL(sql,nil,false,params);
try
if Not adataset.Eof then
begin
Result:=adataset.Fields[0].AsVariant;
end;
finally
adataset.free;
end;
end;
function TRpBaseReport.ReOpenOp(datasetname:String;sql:Widestring):BOolean;
var
adata:TRpDatainfoItem;
index,i:integer;
begin
Result:=false;
index:=datainfo.IndexOf(datasetname);
if index<0 then
exit;
adata:=datainfo.Items[index];
adata.Disconnect;
// Evaluates from evaluator all parameters
for i:=0 to params.Count-1 do
begin
params.Items[i].LastValue:=evaluator.EvaluateText('M.'+params.Items[i].Name);
end;
adata.SQLOverride:=sql;
adata.Connect(DatabaseInfo,Params);
end;
function TRpBaseReport.Newlanguage(alanguage:integer):integer;
begin
Result:=FLanguage;
// Setting the property, sets the new language
// for the evaluator and the parameters
Language:=aLanguage;
end;
function TRpBaseReport.OnParamInfo(ParamName:String;index:integer):String;
var
param:TRpParam;
i,ind:integer;
begin
Result:='';
param:=Params.FindParam(UpperCase(ParamName));
if Assigned(param) then
begin
if param.ParamType in [rpparammultiple,rpparamlist,rpparamsubstlist] then
begin
case index of
0:
// Parameter value as string
Result:=param.AsString;
1:
begin
// Parameter value as multiple line string, real values
if param.ParamType=rpparammultiple then
begin
for i:=0 to param.Selected.Count-1 do
begin
ind:=StrToInt(param.Selected.Strings[i]);
if param.Values.Count>ind then
begin
if Length(Result)>0 then
Result:=Result+#10+param.Values.Strings[ind]
else
Result:=param.Values.Strings[ind];
end;
end;
end
else
begin
if ((param.ParamType=rpparamlist) or (param.ParamType=rpparamsubstlist)) then
Result:=param.ListValue;
end;
end;
2:
begin
// Parameter value as multiple line string, indexes selected
if param.ParamType=rpparammultiple then
begin
for i:=0 to param.Selected.Count-1 do
begin
ind:=StrToInt(param.Selected.Strings[i]);
if Length(Result)>0 then
Result:=Result+#10+IntToStr(ind)
else
Result:=IntToStr(ind);
end;
end
else
begin
Result:=param.AsString;
end;
end;
3:
begin
// Parameter value as multiple line string, user selection
if param.ParamType=rpparammultiple then
begin
for i:=0 to param.Selected.Count-1 do
begin
ind:=StrToInt(param.Selected.Strings[i]);
if param.Items.Count>ind then
begin
if Length(Result)>0 then
Result:=Result+#10+param.Items.Strings[ind]
else
Result:=param.Items.Strings[ind];
end;
end;
end
else
begin
Result:=param.AsString;
end;
end;
4:
begin
// Parameter value as multiple line string, possible values as user see
for i:=0 to param.Items.Count-1 do
begin
if Length(Result)>0 then
Result:=Result+#10+param.Items.Strings[i]
else
Result:=param.Items.Strings[i];
end;
end;
5:
begin
// Parameter value as multiple line string, possible values as real values
for i:=0 to param.Values.Count-1 do
begin
if Length(Result)>0 then
Result:=Result+#10+param.Values.Strings[i]
else
Result:=param.Values.Strings[i];
end;
end;
6:
begin
// Datasets related to the param
for i:=0 to param.Datasets.Count-1 do
begin
if Length(Result)>0 then
Result:=Result+#10+param.Datasets.Strings[i]
else
Result:=param.Datasets.Strings[i];
end;
end;
7:
begin
// Description
Result:=param.Description;
end;
8:
begin
// Description
Result:=param.Hint;
end;
9:
begin
// Description
Result:=param.ErrorMessage;
end;
10:
begin
// Description
Result:=param.Validation;
end;
end;
end
else
begin
case index of
6:
begin
for i:=0 to param.Datasets.Count-1 do
begin
if Length(Result)>0 then
Result:=Result+#10+param.Datasets.Strings[i]
else
Result:=param.Datasets.Strings[i];
end;
end;
7:
begin
// Description
Result:=param.Description;
end;
8:
begin
// Description
Result:=param.Hint;
end;
9:
begin
// Description
Result:=param.ErrorMessage;
end;
10:
begin
// Description
Result:=param.Validation;
end;
else
Result:=param.AsString;
end;
end;
end;
end;
function TRpBaseReport.RequestPage(pageindex:integer):boolean;
var
asyncexec:Boolean;
begin
AsyncExec:=AsyncExecution;;
if (LastPage) then
begin
Result:=true;
exit;
end;
if (TwoPass) then
begin
AsyncExec:=false;
if (MAX_PAGECOUNT<>pageindex) then
begin
Result:=RequestPage(MAX_PAGECOUNT);
exit;
end;
end;
if (pageindex<(metafile.CurrentPageCount-1)) then
begin
Result:=LastPage;
exit;
end;
if (FExecuting) then
begin
while ((FExecuting) AND (metafile.CurrentPageCount<=pageindex)) do
begin
{$IFDEF MSWINDOWS}
WaitForSingleObject(FThreadExec.Handle,100);
{$ENDIF}
{$IFDEF LINUX}
sleep(100);
{$ENDIF}
// FThreadExec.WaitFor;
// WairForSingleObject(threadexec.handle);
end;
Result:=LastPage;
exit;
end;
if (AsyncExec) then
begin
Printingonepass:=false;
PrintNextPage();
if not LastPage then
begin
fintpageindex:=MAX_PAGECOUNT;
FExecuting:=true;
try
FThreadExec:=TThreadExecReport.Create(true);
FThreadExec.Report:=self;
AbortingThread:=false;
FThreadExec.Resume;
except
FExecuting:=false;
FThreadExec.free;
FThreadExec:=nil;
raise;
end;
while ((FExecuting) AND (metafile.CurrentPageCount<=pageindex)) do
begin
{$IFDEF MSWINDOWS}
WaitForSingleObject(FThreadExec.Handle,100);
{$ENDIF}
{$IFDEF LINUX}
sleep(100);
{$ENDIF}
end;
end;
end
else
begin
if Assigned(FThreadExec) then
begin
FThreadExec.Terminate;
FThreadExec:=nil;
end;
fintpageindex:=pageindex;
DoPrintInternal();
end;
Result:=LastPage;
end;
procedure TRpBaseReport.DoPrintInternal;
begin
try
if (not LastPage) then
begin
CheckProgress(false);
while (not PrintNextPage()) do
begin
CheckProgress(false);
if (PageNum>MAX_PAGECOUNT) then
Raise Exception.Create(SRpMaximumPages+' - '+IntToStr(MAX_PAGECOUNT));
if (PageNum>=fintpageindex) then
break;
if (LastPage) then
break;
if AbortingThread then
break;
end;
end;
FExecuting:=false;
CheckProgress(false);
except
on E:Exception do
begin
FExecuting:=false;
if (FThreadExec=nil) then
raise;
if (not (AbortingThread)) then
begin
if Assigned(OnWorkAsyncError) then
OnWorkAsyncError(E.Message)
else
raise;
end;
end;
end;
end;
procedure TRpBaseReport.StopWork;
begin
if Fexecuting then
begin
if Assigned(FThreadExec) then
begin
AbortingThread:=true;
FThreadExec.Terminate;
FExecuting:=false;
FThreadExec:=nil;
end;
end;
end;
procedure TRpBaseReport.SetLanguage(index:integer);
begin
FLanguage:=index;
Params.Language:=index;
if Assigned(FEvaluator) then
FEvaluator.Language:=FLanguage;
end;
procedure TThreadExecReport.DoProgress;
begin
docancel:=false;
report.FOnProgress(report,docancel);
end;
procedure TThreadExecReport.Execute;
begin
report.DoPrintInternal;
end;
procedure TRpBaseReport.AddReportItemsToEvaluator(eval:TRpEvaluator);
var
i:integeR;
begin
// Insert params into rpEvaluator
for i:=0 to Params.Count-1 do
begin
if eval.Searchidentifier(params.items[i].Name)=nil then
eval.NewVariable(params.items[i].Name,params.items[i].Value);
end;
// Here identifiers are added to evaluator
for i:=0 to Identifiers.Count-1 do
begin
if FIdentifiers.Objects[i] is TRpExpression then
begin
eval.AddVariable(FIdentifiers.Strings[i],
TRpExpression(FIdentifiers.Objects[i]).IdenExpression);
end
else
if FIdentifiers.Objects[i] is TRpChart then
begin
eval.AddVariable(FIdentifiers.Strings[i],
TRpChart(FIdentifiers.Objects[i]).IdenChart);
end
end;
// Compatibility with earlier versions
eval.AddVariable('PAGINA',fidenpagenum);
eval.AddVariable('NUMPAGINA',fidenpagenumgroup);
// Insert page number and other variables
eval.AddVariable('PAGE',fidenpagenum);
eval.AddVariable('PAGENUM',fidenpagenumgroup);
eval.AddVariable('LANGUAGE',fidenlanguage);
// Free space and sizes
eval.AddVariable('FREE_SPACE_TWIPS',fidenfreespace);
eval.AddVariable('PAGEWIDTH',fidenpagewidth);
eval.AddVariable('PAGEHEIGHT',fidenpageheight);
eval.AddVariable('CURRENTGROUP',fidencurrentgroup);
eval.AddVariable('FIRSTSECTION',fidenfirstsection);
eval.AddVariable('FREE_SPACE_CMS',fidenfreespacecms);
eval.AddVariable('FREE_SPACE_INCH',fidenfreespaceinch);
eval.AddIden('EOF',fideneof);
end;
procedure TRpBaseReport.LoadExternals;
begin
end;
function TRpBaseReport.CheckParameters(paramlist:TRpParamList;var paramname,amessage:string):Boolean;
var
i:integer;
validation:widestring;
errormessage:widestring;
aresult:Variant;
paramtemp:TRpParamList;
begin
paramtemp:=nil;
if paramlist<>params then
paramtemp:=TRpParamList.Create(nil);
try
if Assigned(paramtemp) then
paramtemp.Assign(params);
try
if Assigned(paramtemp) then
params.Assign(paramlist);
InitEvaluator;
AddReportItemsToEvaluator(FEvaluator);
Result:=true;
for i:=0 to Params.Count-1 do
begin
validation:=Params.Items[i].Validation;
errormessage:=Params.Items[i].ErrorMessage;
if Length(validation)>0 then
begin
aresult:=Evaluator.EvaluateText(validation);
if not VarIsNull(aresult) then
begin
if VarIsBoolean(aresult) then
begin
if not aresult then
begin
paramname:=Params.Items[i].Name;
amessage:=errormessage;
Result:=false;
break;
end;
end;
end;
end;
end;
finally
if Assigned(paramtemp) then
params.Assign(paramtemp);
end;
finally
if Assigned(paramtemp) then
paramtemp.free;
end;
end;
function TRpBaseReport.IsDotNet:boolean;
begin
Result:=false;
if Databaseinfo.Count>0 then
if (Databaseinfo.Items[0].Driver in [rpdatadriver,rpdotnet2driver]) then
Result:=true;
end;
end.