File: lr_crosstab.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (1247 lines) | stat: -rw-r--r-- 35,996 bytes parent folder | download | duplicates (2)
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
{ LazReport cross-tab control

  Copyright (C) 2014 alexs alexs75.at.yandex.ru

  This library is free software; you can redistribute it and/or modify it
  under the terms of the GNU Library General Public License as published by
  the Free Software Foundation; either version 2 of the License, or (at your
  option) any later version with the following modification:

  As a special exception, the copyright holders of this library give you
  permission to link this library with independent modules to produce an
  executable, regardless of the license terms of these independent modules,and
  to copy and distribute the resulting executable under terms of your choice,
  provided that you also meet, for each linked independent module, the terms
  and conditions of the license of that module. An independent module is a
  module which is not derived from or based on this library. If you modify
  this library, you may extend this exception to your version of the library,
  but you are not obligated to do so. If you do not wish to do so, delete this
  exception statement from your version.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  for more details.

  You should have received a copy of the GNU Library General Public License
  along with this library; if not, write to the Free Software Foundation,
  Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.
}

unit lr_CrossTab;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LR_Class, Graphics, LR_DSet, lr_CrossArray, DB;

const
  CrossFuncCount = 6;
  CrossFuncList : array [0..CrossFuncCount - 1] of string =
     ('NONE', 'SUM', 'MIN', 'MAX', 'AVG', 'COUNT');
type
  TlrCrossObject = class(TComponent)

  end;

type
  { TlrCrossDesignView }

  TlrCrossDesignView = class(TfrCustomMemoView)
  public
    constructor Create(AOwnerPage:TfrPage); override;
    destructor Destroy; override;
  published
    property Cursor;
    property DetailReport;
    property Font;
    property Alignment;
    property Layout;
    property Angle;
    property WordBreak;
    property WordWrap;
//    property AutoSize;
//    property HideDuplicates;
    property HideZeroValues;
    property FillColor;
    property Memo;
    property Script;
    property Frames;
    property FrameColor;
    property FrameStyle;
    property FrameWidth;
    property Format;
    property FormatStr;
//    property Restrictions;
    property OnClick;
    property OnMouseEnter;
    property OnMouseLeave;
  end;

  { TlrCrossDesignDataView }

  TlrCrossDesignDataView = class(TlrCrossDesignView)
  private
    FAlternativeColor: TColor;
  public
    constructor Create(AOwnerPage:TfrPage); override;
    procedure Assign(Source: TPersistent); override;
    procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
    procedure SavetoXML(XML: TLrXMLConfig; const Path: String); override;
  published
    property AlternativeColor:TColor read FAlternativeColor write FAlternativeColor default clNone; //AlternativeFillColor
  end;

  { TlrCrossView }

  TlrCrossView = class(TfrStretcheable)
  private
    FExVarArray:TExVarArray;
    FRowTotalArray : TExRow;
    FColTotalArray : TExRow;
    FShowTotalCHCell: Boolean;
    FShowTotalRHCell: Boolean;
    FTotal : Variant;
    FData:TDataSet;

    FCellFields: TStrings;
    FColumnFields: TStrings;
    FRowFields: TStrings;
    FDataSetName: string;
    FShowColumnHeader: Boolean;
    FShowColumnTotal: Boolean;
    FShowCorner: Boolean;
    FShowGrandTotal: Boolean;
    FShowRowHeader: Boolean;
    FShowRowTotal: Boolean;
    FShowTitle: Boolean;
    TextHeight: Integer;
    LineSpacing: Integer;

    FDataCell:TlrCrossDesignDataView;
    FRowTitleCell:TlrCrossDesignView;
    FRowTotalCell:TlrCrossDesignView;
    FColTitleCell:TlrCrossDesignView;
    FColTotalCell:TlrCrossDesignView;
    FGrandTotalCell:TlrCrossDesignView;

    FTotalCHCell:TlrCrossDesignView;
    FTotalRHCell:TlrCrossDesignView;

    FBandDataRowRT : TfrBandView;
    FBandCrossRowRT : TfrBandView;

    procedure InitCrossData;
    procedure DoneCrossData;
    procedure CreateDesignObjects;
    procedure SetCellFields(AValue: TStrings);
    procedure SetColTitleCell(AValue: TlrCrossDesignView);
    procedure SetColTotalCell(AValue: TlrCrossDesignView);
    procedure SetColumnFields(AValue: TStrings);
    procedure SetDataCell(AValue: TlrCrossDesignDataView);
    procedure SetGrandTotalCell(AValue: TlrCrossDesignView);
    procedure SetRowFields(AValue: TStrings);

    procedure OnPrintColumn(ColNo: Integer; var AWidth: Integer);
    procedure OnEnterRect(AMemo: TStringList; AView: TfrView);
    procedure OnExecScript(frObject:TfrObject; AScript:TfrScriptStrings);

    procedure SetRowTitleCell(AValue: TlrCrossDesignView);
    procedure SetRowTotalCell(AValue: TlrCrossDesignView);
    procedure SetTotalCHCell(AValue: TlrCrossDesignView);
    procedure SetTotalRHCell(AValue: TlrCrossDesignView);
  protected
    function CalcHeight: Integer; override;
    function MinHeight: Integer; override;
    function RemainHeight: Integer; override;
    procedure SetName(const AValue: string); override;
    procedure PrepareObject; override;
    procedure AfterCreate;override;
  public
    constructor Create(AOwnerPage:TfrPage);override;
    destructor Destroy; override;

    procedure Print(Stream: TStream); override;
    procedure Draw(aCanvas: TCanvas); override;
    procedure BeginUpdate; override;
    procedure EndUpdate; override;

    procedure Assign(Source: TPersistent); override;
    procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
    procedure SavetoXML(XML: TLrXMLConfig; const Path: String); override;

    procedure LoadFromStream(Stream: TStream); override;
    procedure SaveToStream(Stream: TStream); override;

    function ColCount:integer;
    function RowCount:integer;

  published
    property ShowColumnHeader: Boolean read FShowColumnHeader write FShowColumnHeader default True;
    property ShowColumnTotal: Boolean read FShowColumnTotal write FShowColumnTotal default True;
    property ShowCorner: Boolean read FShowCorner write FShowCorner default True;
    property ShowRowHeader: Boolean read FShowRowHeader write FShowRowHeader default True;
    property ShowRowTotal: Boolean read FShowRowTotal write FShowRowTotal default True;
    property ShowTitle: Boolean read FShowTitle write FShowTitle default True;
    property ShowGrandTotal: Boolean read FShowGrandTotal write FShowGrandTotal default True;
    property ShowTotalCHCell: Boolean read FShowTotalCHCell write FShowTotalCHCell default True;
    property ShowTotalRHCell: Boolean read FShowTotalRHCell write FShowTotalRHCell default True;

    property DataCell:TlrCrossDesignDataView read FDataCell write SetDataCell;
    property RowTitleCell:TlrCrossDesignView read FRowTitleCell write SetRowTitleCell;
    property RowTotalCell:TlrCrossDesignView read FRowTotalCell write SetRowTotalCell;
    property ColTitleCell:TlrCrossDesignView read FColTitleCell write SetColTitleCell;
    property ColTotalCell:TlrCrossDesignView read FColTotalCell write SetColTotalCell;
    property GrandTotalCell:TlrCrossDesignView read FGrandTotalCell write SetGrandTotalCell;
    property TotalCHCell:TlrCrossDesignView read FTotalCHCell write SetTotalCHCell;
    property TotalRHCell:TlrCrossDesignView read FTotalRHCell write SetTotalRHCell;

    property Restrictions;
    property FillColor;
    property DataSet:string read FDataSetName write FDataSetName;
    property CellFields:TStrings read FCellFields write SetCellFields;
    property ColumnFields:TStrings read FColumnFields write SetColumnFields;
    property RowFields:TStrings read FRowFields write SetRowFields;
  end;

const
  NumericFieldTypes = [ftSmallint, ftInteger, ftWord, ftFloat, ftCurrency,
    ftBCD, ftAutoInc, ftLargeint];

implementation
uses lr_CrossTabEditor, LR_Utils, LR_Const, strutils, variants, Math;

{$R *.res}

var
  lrBMPCrossView : TBitMap = nil;

{ TlrCrossView }

type

  { TlrCrossPage }

  TlrCrossPage = class(TfrPage)
    constructor Create(AOwnerPage:TfrPage); override;
  end;

  TlrHackObject = class(TfrObject);

{ TlrCrossDesignDataView }

constructor TlrCrossDesignDataView.Create(AOwnerPage: TfrPage);
begin
  inherited Create(AOwnerPage);
  FAlternativeColor:=clNone;
end;

procedure TlrCrossDesignDataView.Assign(Source: TPersistent);
begin
  inherited Assign(Source);
  if Source is TlrCrossDesignDataView then
    FAlternativeColor:=TlrCrossDesignDataView(Source).FAlternativeColor;
end;

procedure TlrCrossDesignDataView.LoadFromXML(XML: TLrXMLConfig;
  const Path: String);
begin
  inherited LoadFromXML(XML, Path);
  FAlternativeColor := StringToColor(XML.GetValue(Path+'AlternativeColor/Value', 'clNone'));
end;

procedure TlrCrossDesignDataView.SavetoXML(XML: TLrXMLConfig; const Path: String
  );
begin
  inherited SavetoXML(XML, Path);
  XML.SetValue(Path+'AlternativeColor/Value', ColorToString(FAlternativeColor));
end;

{ TlrCrossDesignView }

constructor TlrCrossDesignView.Create(AOwnerPage: TfrPage);
begin
  inherited Create(AOwnerPage);
  FDesignOptions:=FDesignOptions + [doUndoDisable, doChildComponent];
  Restrictions:=Restrictions + [lrrDontSize, lrrDontMove, lrrDontDelete];
//  Frames:=[frbLeft, frbTop, frbRight, frbBottom];
  FrameStyle:=frsSolid;
end;

destructor TlrCrossDesignView.Destroy;
begin
  if Assigned(OwnerPage) then
    OwnerPage.Objects.Remove(Self);
  inherited Destroy;
end;

{ TlrCrossPage }

constructor TlrCrossPage.Create(AOwnerPage: TfrPage);
begin
  inherited Create(AOwnerPage);
  PrintToPrevPage:=true;
end;

function TlrCrossView.ColCount: integer;
begin
  if Assigned(FExVarArray) then
    Result:=FExVarArray.ColCount
  else
    Result:=0;
end;

function TlrCrossView.RowCount: integer;
begin
  if Assigned(FExVarArray) then
    Result:=FExVarArray.RowCount
  else
    Result:=0;
end;

procedure TlrCrossView.InitCrossData;
var
  FD:TField;
  FR:TField;
  FC:TField;
  S: String;
  P:TBookMark;
  V, VT, SR, SC:Variant;
  FCalcTotal:boolean;
  j: Integer;
  i: Integer;
  FuncNo:integer;
  S1: String;
  ExItem:TExItem;

function DoFunc(V1, V2:Variant):Variant;
begin
  case FuncNo of
    1:Result:=V1 + V2;     //SUM
    2:if V1<V2 then Result:=V1
      else Result:=V2; //MIN
    3:if V1>V2 then Result:=V1
       else Result:=V2; //MAX
  else
    Result:=V2; //NONE
  end
  //COUNT
  //AVG
end;

begin
  DoneCrossData;

  FData:=nil;
  FD:=nil;
  FR:=nil;
  FC:=nil;
  FuncNo:=1;

  FExVarArray:=TExVarArray.Create;
  FRowTotalArray := TExRow.Create;
  FColTotalArray := TExRow.Create;

  FData:=frGetDataSet(DataSet);
  if (not Assigned(FData)) or not (FData.Active) then
    exit;

  if CellFields.Count>0 then
  begin
    S:=CellFields[0];
    if Pos('|', S)>0 then
    begin
      S1:=Copy2SymbDel(S, '|');
      for i:=0 to CrossFuncCount-1 do
        if CrossFuncList[i] = S then
        begin
          FuncNo:=i;
          break;
        end;
      S:=S1;
    end;

    FD:=FData.FindField(S);

  end;

  if RowFields.Count>0 then
    FR:=FData.FindField(RowFields[0]);

  if ColumnFields.Count>0 then
    FC:=FData.FindField(ColumnFields[0]);

  if not (Assigned(FD) and Assigned(FR) and Assigned(FC)) then
    exit;


  FCalcTotal:=FD.DataType in NumericFieldTypes;

  P:=FData.GetBookmark;
  FData.DisableControls;
  try

    FData.First;
    while not FData.EOF do
    begin
      if FCalcTotal then
      begin
        V:=FExVarArray.Cell[FC.Value, FR.Value];
        if V = null then
        begin
          if FuncNo in [2,3] then
            V:=FD.AsFloat
          else
            V:=0;
        end;
        FExVarArray.Cell[FC.Value, FR.Value]:=DoFunc(V, FD.AsFloat);
      end
      else
        FExVarArray.Cell[FC.Value, FR.Value]:=FD.DisplayText;

      ExItem:=FExVarArray.CellData[FC.Value, FR.Value];
      if Assigned(ExItem) and not ExItem.IsBookmarkValid then
        ExItem.SaveBookmark(FData);
      FData.Next;
    end;
  finally
    FData.GotoBookmark(P);
    FData.FreeBookmark(P);
    FData.EnableControls;
  end;

  if FCalcTotal then
  begin
    FTotal:=0;
    for j:=0 to FExVarArray.RowCount - 1 do
    begin
      SR:=FExVarArray.RowHeader[j];

      if FuncNo in [2,3] then
        VT:=FExVarArray.Cell[FExVarArray.ColHeader[0], SR]
      else
        VT:=0;

      for i:=0 to FExVarArray.ColCount - 1 do
      begin
        SC:=FExVarArray.ColHeader[i];
        V:=FExVarArray.Cell[SC, SR];
        if V<>null then
          VT:=DoFunc(VT, V);
      end;
      FRowTotalArray[SR]:=VT;
      FTotal:=DoFunc(FTotal, VT);
    end;

    for i:=0 to FExVarArray.ColCount - 1 do
    begin
      SC:=FExVarArray.ColHeader[i];

      if FuncNo in [2,3] then
        VT:=FExVarArray.Cell[SC, FExVarArray.RowHeader[0]]
      else
        VT:=0;

      for j:=0 to FExVarArray.RowCount - 1 do
      begin
        SR:=FExVarArray.RowHeader[j];
        V:=FExVarArray.Cell[SC, SR];
        if V<>null then
          VT:=DoFunc(VT, V);
      end;
      FColTotalArray[SC]:=VT;
    end;
  end;
end;

procedure TlrCrossView.DoneCrossData;
begin
  if Assigned(FExVarArray) then
    FreeAndNil(FExVarArray);
  if Assigned(FRowTotalArray) then
    FreeAndNil(FRowTotalArray);

  if Assigned(FColTotalArray) then
    FreeAndNil(FColTotalArray);

  FTotal:=null;
end;

procedure TlrCrossView.CreateDesignObjects;

function DoCreateDesignObjects(AName, ACaption:string; AWidth, AHeight:integer):TlrCrossDesignView;
begin
  Result:=TlrCrossDesignView.Create(OwnerPage);
  Result.Name:=Name+'_'+AName;
  Result.Memo.Text:=ACaption;
  Result.dx:=AWidth;
  Result.dY:=AHeight;
end;

begin
  if Assigned(FDataCell) then exit;

  FDataCell:=TlrCrossDesignDataView.Create(OwnerPage);
  FDataCell.Name:=Name+'_'+'DataCell';
  FDataCell.Memo.Text:=sCrossTabData;
  FDataCell.dx:=60;
  FDataCell.dY:=18;
//  DoCreateDesignObjects('DataCell', 'Data', 60, 18);

  FRowTitleCell:=DoCreateDesignObjects('RowTitleCell', sCrossTabRowTitle, 60, 18);
  FRowTotalCell:=DoCreateDesignObjects('RowTotalCell', sCrossTabRowTotal, 60, 18);
  FColTitleCell:=DoCreateDesignObjects('ColTitleCell', sCrossTabColTitle, 60, 18);
  FColTotalCell:=DoCreateDesignObjects('ColTotalCell', sCrossTabColTotal, 60, 18);
  FGrandTotalCell:=DoCreateDesignObjects('GrandTotalCell', sCrossTabGranTotal, 60, 18);

  FTotalCHCell:=DoCreateDesignObjects('TotalCHCell', sCrossTabTotalCHCell, 60, 18);
  FTotalRHCell:=DoCreateDesignObjects('TotalRHCell', sCrossTabTotalRHCell, 60, 18);

  FDataCell.Restrictions:=FDataCell.Restrictions - [lrrDontSize];
  FRowTitleCell.Restrictions:=FDataCell.Restrictions - [lrrDontSize];
  FRowTotalCell.Restrictions:=FDataCell.Restrictions - [lrrDontSize];
end;

procedure TlrCrossView.SetCellFields(AValue: TStrings);
begin
  FCellFields.Assign(AValue);
end;

procedure TlrCrossView.SetColTitleCell(AValue: TlrCrossDesignView);
begin
  FColTitleCell.Assign(AValue);
end;

procedure TlrCrossView.SetColTotalCell(AValue: TlrCrossDesignView);
begin
  FColTotalCell.Assign(AValue);
end;

procedure TlrCrossView.SetColumnFields(AValue: TStrings);
begin
  FColumnFields.Assign(AValue);
end;

procedure TlrCrossView.SetDataCell(AValue: TlrCrossDesignDataView);
begin
  FDataCell.Assign(AValue);
end;

procedure TlrCrossView.SetGrandTotalCell(AValue: TlrCrossDesignView);
begin
  FGrandTotalCell.Assign(AValue);
end;

procedure TlrCrossView.SetRowFields(AValue: TStrings);
begin
  FRowFields.Assign(AValue);
end;

procedure TlrCrossView.OnPrintColumn(ColNo: Integer; var AWidth: Integer);
begin
{
if (ColNo > 0) and (ColNo <= FRxColInfoList.Count) then
    Width := TRxColInfo(FRxColInfoList[ColNo-1]).ColWidth;
}
  Width := FDataCell.DX;
end;

procedure TlrCrossView.OnEnterRect(AMemo: TStringList; AView: TfrView);
var
  S: String;
  ColNo: Integer;
  RecNo: Integer;
  V, SC, SR : Variant;
  ExItem:TExItem;
begin
  ColNo:=FBandCrossRowRT.Parent.DataSet.RecNo;
  RecNo:=FBandDataRowRT.Parent.DataSet.RecNo;

  S:=AMemo[0];
  if S='-Cell-' then
  begin
    SC:=FExVarArray.ColHeader[ColNo];
    SR:=FExVarArray.RowHeader[RecNo];

    V:=FExVarArray.Cell[SC, SR];
    if V<>null then
      S:=CurReport.FormatValue(V, AView.Format, AView.FormatStr)
    else
      S:='';

    if (DataCell.AlternativeColor <> clNone) and (RecNo  mod 2 = 1) then
      AView.FillColor:=DataCell.AlternativeColor
    else
      AView.FillColor:=DataCell.FillColor;

    ExItem:=FExVarArray.CellData[SC, SR];
    if Assigned(ExItem) and ExItem.IsBookmarkValid then
      ExItem.GotoBookmark;
  end
  else
  if S = '-RowTitle-' then
  begin
    S:=FExVarArray.RowHeader[RecNo];
  end
  else
  if S = '-ColTitle-' then
  begin
    S:=FExVarArray.ColHeader[ColNo];
  end
  else
  if S = '-RowFooter-' then
  begin
    SR:=FExVarArray.RowHeader[RecNo];
    SC:=FExVarArray.ColHeader[ColNo];
    V:=FRowTotalArray[SR];
    if V<>null then
      S:=CurReport.FormatValue(V, AView.Format, AView.FormatStr)
    else
      S:='';
  end
  else
  if S= '-ColFooter-' then
  begin
    SR:=FExVarArray.RowHeader[RecNo];
    SC:=FExVarArray.ColHeader[ColNo];
    V:=FColTotalArray[SC];
    if V<>null then
      S:=CurReport.FormatValue(V, AView.Format, AView.FormatStr)
    else
      S:='';
  end
  else
  if S = '-GrandTotal-' then
  begin
    if FTotal<>null then
      S:=CurReport.FormatValue(FTotal, AView.Format, AView.FormatStr)
    else
      S:='';
  end;

  AMemo[0]:= S;
end;

procedure TlrCrossView.SetRowTitleCell(AValue: TlrCrossDesignView);
begin
  FRowTitleCell.Assign(AValue);
end;

procedure TlrCrossView.SetRowTotalCell(AValue: TlrCrossDesignView);
begin
  FRowTotalCell.Assign(AValue);
end;

procedure TlrCrossView.SetTotalCHCell(AValue: TlrCrossDesignView);
begin
  FTotalCHCell.Assign(AValue);
end;

procedure TlrCrossView.SetTotalRHCell(AValue: TlrCrossDesignView);
begin
  FTotalRHCell.Assign(AValue);
end;

function TlrCrossView.CalcHeight: Integer;
var
  RC:integer;
begin
  TextHeight:=20;
  RC:=RowCount;
  if RC>0 then
    RC:=RC + Ord(FShowColumnHeader) + Ord(FShowColumnTotal);
  Result := RC * TextHeight;
end;

function TlrCrossView.MinHeight: Integer;
begin
  Result := CalcHeight;
end;

function TlrCrossView.RemainHeight: Integer;
begin
  Result := CalcHeight;
end;

procedure TlrCrossView.SetName(const AValue: string);
begin
  inherited SetName(AValue);
  if Assigned(FDataCell) then
  begin
    FDataCell.Name:=Name+'_'+'Data';
    FRowTitleCell.Name:=Name+'_'+'RowTitleCell';
    FRowTotalCell.Name:=Name+'_'+'RowTotalCell';
    FColTitleCell.Name:=Name+'_'+'ColTitleCell';
    FColTotalCell.Name:=Name+'_'+'ColTotalCell';
    FGrandTotalCell.Name:=Name+'_'+'GrandTotalCell';
    TotalCHCell.Name:=Name+'_'+'TotalCHCell';
    TotalRHCell.Name:=Name+'_'+'TotalRHCell';
  end;
end;

procedure TlrCrossView.PrepareObject;
begin
  inherited PrepareObject;
  InitCrossData;
end;

procedure TlrCrossView.AfterCreate;
begin
  inherited AfterCreate;
{ TODO : Set default size }
//  DX:=10 + 22 * 3;
end;

procedure TlrCrossView.OnExecScript(frObject: TfrObject;
  AScript: TfrScriptStrings);
var
  M:TfrMemoView;
  S: String;

  ColNo: Integer;
  RecNo: Integer;
  V, SC, SR : Variant;
  ExItem:TExItem;

begin
  ColNo:=FBandCrossRowRT.Parent.DataSet.RecNo;
  RecNo:=FBandDataRowRT.Parent.DataSet.RecNo;

  M:=TfrMemoView(frObject);
  S:= M.Memo[0];
  if S='-Cell-' then
  begin
    SC:=FExVarArray.ColHeader[ColNo];
    SR:=FExVarArray.RowHeader[RecNo];

    ExItem:=FExVarArray.CellData[SC, SR];
    if Assigned(ExItem) and ExItem.IsBookmarkValid then
    begin
      frVariables['CrossViewIsEmpty']:=false;
      ExItem.GotoBookmark;
    end
    else
      frVariables['CrossViewIsEmpty']:=true;



    frInterpretator.DoScript(AScript);
  end
end;

procedure TlrCrossView.Print(Stream: TStream);
var
  FPage : TlrCrossPage;

  FBandDataHeader : TfrBandView;
  FBandDataFooter : TfrBandView;

  FBandCrossHeader : TfrBandView;
  FBandCrossFooter : TfrBandView;

  FBandDataRow : TfrBandView;
  FBandCrossRow : TfrBandView;

  FYPos : integer;
  FView : TfrMemoView;
  FXPos: Integer;
  FSavePage : TfrPage;
  FSavePrintColumnEvent :TPrintColumnEvent;
  FSaveEnterRectEvent : TEnterRectEvent;

  XX:integer;
  YY: Integer;
begin
  Memo1.Assign(Memo);
  CurReport.InternalOnEnterRect(Memo1, Self);
  frInterpretator.DoScript(Script);
  if not Visible then Exit;


  FSavePage := CurPage;
  FSavePrintColumnEvent:=CurReport.OnPrintColumn;
  FSaveEnterRectEvent:=CurReport.OnEnterRect;

  CurReport.OnPrintColumn:=@OnPrintColumn;
  CurReport.OnEnterRect:=@OnEnterRect;

  BeginDraw(Canvas);

  FYPos:=0;
  FXPos:=Self.x;


  FPage:=TlrCrossPage.Create(nil);
  FPage.ChangePaper(OwnerPage.pgSize, OwnerPage.Width, OwnerPage.Height, OwnerPage.Orientation);
  FPage.UseMargins:=OwnerPage.UseMargins;
  FPage.Margins.AsRect:=OwnerPage.Margins.AsRect;

  if FShowTotalRHCell then
  begin
    FView := frCreateObject(gtMemo, '', FPage) as TfrMemoView;
    FView.Assign(FTotalRHCell);
    FView.SetBounds(FXPos, FYPos, FTotalRHCell.DX, FTotalRHCell.dy);
  end;


 if FShowColumnHeader then
  begin
    XX:=FXPos;
    if FShowRowHeader then
      XX:=XX + FRowTitleCell.DX + 2;

    FBandDataHeader := TfrBandView(frCreateObject(gtBand, '', FPage));
    FBandDataHeader.BandType := btMasterHeader;
    FBandDataHeader.SetBounds(XX, 0, 1000, 18);
    FBandDataHeader.Name:=Name+'_DataHeader';
    FBandDataHeader.Stretched:=true;

    FView := frCreateObject(gtMemo, '', FPage) as TfrMemoView;
    FView.Assign(FColTitleCell);
    FView.SetBounds(XX, FYPos, FDataCell.DX, FColTitleCell.dy);
    FView.Memo.Text:='-ColTitle-';
    FYPos := FYPos + FColTitleCell.dY + 2;
  end;

  if FShowRowHeader or FShowTotalRHCell then
  begin
    FBandCrossHeader := TfrBandView(frCreateObject(gtBand, '', FPage));
    FBandCrossHeader.BandType := btCrossHeader;
    FBandCrossHeader.SetBounds(FXPos, 0, FRowTitleCell.DX, 1000);
    FBandCrossHeader.Name:=Name+'_CrossHeader';

    if FShowRowHeader then
    begin
      FView := frCreateObject(gtMemo, '', FPage) as TfrMemoView;
      FView.Assign(FRowTitleCell);
      FView.SetBounds(FXPos, FYPos, FRowTitleCell.DX, FRowTitleCell.dy);
      FView.Memo.Text:='-RowTitle-';
    end;
    FXPos:=FXPos + FRowTitleCell.DX + 2;
  end;

  //Make main data band
  FBandDataRow := TfrBandView(frCreateObject(gtBand, '', FPage));
  FBandDataRow.BandType := btMasterData;
  FBandDataRow.DataSet := IntToStr(RowCount);
  FBandDataRow.SetBounds(0, FYPos, 1000, 18);
  FBandDataRow.Flags:=FBandDataRow.Flags or flStretched;
  FBandDataRow.Name:=Name+'_MasterData';

  FBandCrossRow := TfrBandView(frCreateObject(gtBand, '', FPage));
  FBandCrossRow.BandType := btCrossData;
  FBandCrossRow.Dataset := IntToStr(ColCount);
  FBandCrossRow.SetBounds(FXPos, 0, FDataCell.DX, 1000);
  FBandCrossRow.Name:=Name+'_CrossData';

  FView := frCreateObject(gtMemo, '', FPage) as TfrMemoView;
  FView.Assign(FDataCell);
  FView.SetBounds(FXPos, FYPos, FDataCell.DX, FDataCell.dy);
  FView.Memo.Text:='-Cell-';
  TlrHackObject(FView).FOnExecScriptEvent:=@OnExecScript;

  if FShowRowTotal or FShowGrandTotal then
  begin
    XX:=FXPos + FDataCell.X + FDataCell.DX + 2;
    FBandCrossFooter := TfrBandView(frCreateObject(gtBand, '', FPage));
    FBandCrossFooter.BandType := btCrossFooter;
    FBandCrossFooter.SetBounds(XX, 0, FRowTotalCell.DX, 1000);
    FBandCrossFooter.Flags:=FBandDataRow.Flags or flStretched;
    FBandCrossFooter.Name:=Name+'_CrossFooter';

    if FShowRowTotal then
    begin
      FView := frCreateObject(gtMemo, '', FPage) as TfrMemoView;
      FView.Assign(FRowTotalCell);
      FView.SetBounds(XX, FYPos, FRowTotalCell.DX, FRowTotalCell.dy);
      FView.Memo.Text:='-RowFooter-';
    end;
  end;

  if FShowColumnTotal or FShowGrandTotal then
  begin
    YY:=FYPos + FDataCell.Y + FDataCell.DY + 2;
    FBandDataFooter := TfrBandView(frCreateObject(gtBand, '', FPage));
    FBandDataFooter.BandType := btMasterFooter;
    FBandDataFooter.SetBounds(0, YY, 1000, FColTotalCell.DY);
    FBandDataFooter.Flags:=FBandDataRow.Flags or flStretched;
    FBandDataFooter.Name:=Name+'_BandDataFooter';

    if FShowColumnTotal then
    begin
      FView := frCreateObject(gtMemo, '', FPage) as TfrMemoView;
      FView.Assign(FColTotalCell);
      FView.SetBounds(FXPos, YY, FColTotalCell.DX, FColTotalCell.DY);
      FView.Memo.Text:='-ColFooter-';
    end;
  end;

  if FShowTotalCHCell then
  begin
    XX:=FXPos + FDataCell.X + FDataCell.DX + 2;
    YY:=FYPos - FColTitleCell.dy - 2;

    FView := frCreateObject(gtMemo, '', FPage) as TfrMemoView;
    FView.Assign(FTotalCHCell);
    FView.SetBounds(XX, YY, FTotalCHCell.DX, FTotalCHCell.DY);
  end;

  if FShowGrandTotal then
  begin
    XX:=FXPos + FDataCell.X + FDataCell.DX + 2;
    YY:=FYPos + FDataCell.Y + FDataCell.DY + 2;

    FView := frCreateObject(gtMemo, '', FPage) as TfrMemoView;
    FView.Assign(FGrandTotalCell);
    FView.SetBounds(XX, YY, FGrandTotalCell.DX, FGrandTotalCell.DY);
    FView.Memo.Text:='-GrandTotal-';
  end;


  FPage.InitReport;
  FBandDataRowRT:=TfrBandView(FPage.FindRTObject(FBandDataRow.Name));
  FBandCrossRowRT:=TfrBandView(FPage.FindRTObject(FBandCrossRow.Name));

  FPage.Mode := pmBuildList;
  FPage.FormPage;

  FPage.CurY := FBandDataRow.y + Self.Y;
  FPage.CurBottomY := FSavePage.CurBottomY;
  FPage.ColCount := 1;

  FPage.PlayFrom := 0;
  while FPage.PlayFrom < FPage.List.Count do
  begin
    if FPage.PlayRecList then
      Inc(FPage.PlayFrom);
  end;

  FPage.DoneReport;
  if Assigned(FSavePage) then
    FSavePage.CurY:=FPage.CurY;
  FPage.Free;

  CurPage:=FSavePage;
  CurReport.OnPrintColumn := FSavePrintColumnEvent;
  CurReport.OnEnterRect   := FSaveEnterRectEvent;

  FBandDataRowRT:=nil;
  FBandCrossRowRT:=nil;
end;

procedure TlrCrossView.Draw(aCanvas: TCanvas);
var
  FY:integer;
  FX: Integer;
begin
  Frames:=[frbLeft, frbTop, frbRight, frbBottom];
  FrameStyle:=frsSolid;
  BeginDraw(aCanvas);
  CalcGaps;

  ShowBackGround;
  ShowFrame;

  FX:=X + 10;
  FY:=Y + 10;

  FTotalRHCell.X:=FX;
  FTotalRHCell.Y:=FY;
  FTotalRHCell.dx:=FRowTitleCell.dx;

  FColTitleCell.X:=FX + FRowTitleCell.dX + 4;
  FColTitleCell.y:=FY;
  FColTitleCell.DX:=FDataCell.DX;

  FTotalCHCell.x:=FColTitleCell.x + FColTitleCell.DX + 4;
  FTotalCHCell.y:=FY;
  FTotalCHCell.DX:=FRowTotalCell.DX;

  Inc(FY, FColTitleCell.dy + 4);

  FRowTitleCell.X:=FX;
  FRowTitleCell.y:=FY;

  FDataCell.x:=FX + FRowTitleCell.dX + 4;
  FDataCell.y:=FY;

  FRowTotalCell.X:=FX + FRowTitleCell.dX + FDataCell.dX + 8;
  FRowTotalCell.y:=FY;

  Inc(FY, FColTitleCell.dy + 4);

  FColTotalCell.X:=FX + FRowTitleCell.dX + 4;
  FColTotalCell.y:=FY;
  FColTotalCell.DX:=FDataCell.DX;


  FGrandTotalCell.X:=FX + FRowTitleCell.dX + FDataCell.dX + 8;
  FGrandTotalCell.y:=FY;
  FGrandTotalCell.DX:=FRowTotalCell.DX;

  aCanvas.Draw(X + dx - 20, Y + dy - 20, lrBMPCrossView);
end;

procedure TlrCrossView.BeginUpdate;
begin
  inherited BeginUpdate;
  FDataCell.BeginUpdate;
  FRowTitleCell.BeginUpdate;
  FRowTotalCell.BeginUpdate;
  FColTitleCell.BeginUpdate;
  FColTotalCell.BeginUpdate;
  FGrandTotalCell.BeginUpdate;
  FTotalCHCell.BeginUpdate;
  FTotalRHCell.BeginUpdate;
end;

procedure TlrCrossView.EndUpdate;
begin
  inherited EndUpdate;
  FDataCell.EndUpdate;
  FRowTitleCell.EndUpdate;
  FRowTotalCell.EndUpdate;
  FColTitleCell.EndUpdate;
  FColTotalCell.EndUpdate;
  FGrandTotalCell.EndUpdate;
  FTotalCHCell.EndUpdate;
  FTotalRHCell.EndUpdate;
end;

constructor TlrCrossView.Create(AOwnerPage: TfrPage);
begin
  inherited Create(AOwnerPage);
  FDesignOptions:= FDesignOptions + [doUndoDisable];

  Typ := gtAddIn;
  BaseName := 'CrossView';
  TextHeight:=0;
  LineSpacing:=2;

  FShowColumnHeader:=True;
  FShowColumnTotal:=True;
  FShowCorner:=True;
  FShowRowHeader:=True;
  FShowRowTotal:=True;
  FShowTitle:=True;
  FShowGrandTotal:=true;
  FShowTotalCHCell:=true;
  FShowTotalRHCell:=true;

  FCellFields:=TStringList.Create;
  FColumnFields:=TStringList.Create;
  FRowFields:=TStringList.Create;

  CreateDesignObjects;
end;

destructor TlrCrossView.Destroy;
begin
  FreeAndNil(FDataCell);
  FreeAndNil(FRowTitleCell);
  FreeAndNil(FRowTotalCell);
  FreeAndNil(FColTitleCell);
  FreeAndNil(FColTotalCell);
  FreeAndNil(FGrandTotalCell);

  FreeAndNil(FCellFields);
  FreeAndNil(FColumnFields);
  FreeAndNil(FRowFields);
  DoneCrossData;
  inherited Destroy;
end;

procedure TlrCrossView.Assign(Source: TPersistent);
begin
  inherited Assign(Source);
  if Source is TlrCrossView then
  begin
    FShowColumnHeader:=TlrCrossView(Source).FShowColumnHeader;
    FShowColumnTotal:=TlrCrossView(Source).FShowColumnTotal;
    FShowCorner:=TlrCrossView(Source).FShowCorner;
    FShowRowHeader:=TlrCrossView(Source).FShowRowHeader;
    FShowRowTotal:=TlrCrossView(Source).FShowRowTotal;
    FShowTitle:=TlrCrossView(Source).FShowTitle;
    FShowGrandTotal:=TlrCrossView(Source).FShowGrandTotal;
    FShowTotalCHCell:=TlrCrossView(Source).FShowTotalCHCell;
    FShowTotalRHCell:=TlrCrossView(Source).FShowTotalRHCell;

    FillColor:=TlrCrossView(Source).FillColor;
    DataSet:=TlrCrossView(Source).DataSet;
    CellFields.Assign(TlrCrossView(Source).CellFields);
    ColumnFields.Assign(TlrCrossView(Source).ColumnFields);
    RowFields.Assign(TlrCrossView(Source).RowFields);


    FDataCell.Assign(TlrCrossView(Source).FDataCell);
    FRowTitleCell.Assign(TlrCrossView(Source).FRowTitleCell);
    FRowTotalCell.Assign(TlrCrossView(Source).FRowTotalCell);
    FColTitleCell.Assign(TlrCrossView(Source).FColTitleCell);
    FColTotalCell.Assign(TlrCrossView(Source).FColTotalCell);
    FGrandTotalCell.Assign(TlrCrossView(Source).FGrandTotalCell);
    FTotalCHCell.Assign(TlrCrossView(Source).FTotalCHCell);
    FTotalRHCell.Assign(TlrCrossView(Source).FTotalRHCell);

  end;
end;

procedure TlrCrossView.LoadFromXML(XML: TLrXMLConfig; const Path: String);
begin
  inherited LoadFromXML(XML, Path);
  FShowColumnHeader:= XML.GetValue(Path+'ShowColumnHeader/Value', true);
  FShowColumnTotal:= XML.GetValue(Path+'ShowColumnTotal/Value', true);
  FShowCorner:= XML.GetValue(Path+'ShowCorner/Value', true);
  FShowRowHeader:= XML.GetValue(Path+'ShowRowHeader/Value', true);
  FShowRowTotal:= XML.GetValue(Path+'ShowRowTotal/Value', true);
  FShowTitle:= XML.GetValue(Path+'ShowTitle/Value', true);
  FShowGrandTotal:= XML.GetValue(Path+'ShowGrandTotal/Value', true);
  FShowTotalCHCell:= XML.GetValue(Path+'ShowTotalCHCell/Value', true);
  FShowTotalRHCell:= XML.GetValue(Path+'ShowTotalRHCell/Value', true);

  FDataSetName:=XML.GetValue(Path+'DataSetName/Value', '');
  FCellFields.Text:=XML.GetValue(Path+'CellFields/Value', '');
  FColumnFields.Text:=XML.GetValue(Path+'ColumnFields/Value', '');
  FRowFields.Text:=XML.GetValue(Path+'RowFields/Value', '');

  BeginUpdate;
  FDataCell.LoadFromXML(XML, Path+'DataCell/');
  FRowTitleCell.LoadFromXML(XML, Path+'RowTitleCell/');
  FRowTotalCell.LoadFromXML(XML, Path+'RowTotalCell/');
  FColTitleCell.LoadFromXML(XML, Path+'ColTitleCell/');
  FColTotalCell.LoadFromXML(XML, Path+'ColTotalCell/');
  FGrandTotalCell.LoadFromXML(XML, Path+'GrandTotalCell/');

  FTotalCHCell.LoadFromXML(XML, Path+'TotalCHCell/');
  FTotalRHCell.LoadFromXML(XML, Path+'TotalRHCell/');
  EndUpdate;

  FDataCell.DY:=18;
  FRowTitleCell.DY:=18;
  FRowTotalCell.DY:=18;
  FColTitleCell.DY:=18;
  FColTotalCell.DY:=18;
  FGrandTotalCell.DY:=18;
  FTotalCHCell.DY:=18;
  FTotalRHCell.DY:=18;
end;

procedure TlrCrossView.SavetoXML(XML: TLrXMLConfig; const Path: String);
begin
  inherited SavetoXML(XML, Path);
  XML.SetValue(Path+'ShowColumnHeader/Value', FShowColumnHeader);
  XML.SetValue(Path+'ShowColumnTotal/Value', FShowColumnTotal);
  XML.SetValue(Path+'ShowCorner/Value'{%H-}, FShowCorner);
  XML.SetValue(Path+'ShowRowHeader/Value', FShowRowHeader);
  XML.SetValue(Path+'ShowRowTotal/Value', FShowRowTotal);
  XML.SetValue(Path+'ShowTitle/Value', FShowTitle);
  XML.SetValue(Path+'ShowGrandTotal/Value', FShowGrandTotal);
  XML.SetValue(Path+'ShowTotalCHCell/Value', FShowTotalCHCell);
  XML.SetValue(Path+'ShowTotalRHCell/Value', FShowTotalRHCell);
  XML.SetValue(Path+'DataSetName/Value', FDataSetName);

  XML.SetValue(Path+'CellFields/Value', FCellFields.Text);
  XML.SetValue(Path+'ColumnFields/Value', FColumnFields.Text);
  XML.SetValue(Path+'RowFields/Value', FRowFields.Text);

  FDataCell.SaveToXML(XML, Path+'DataCell/');
  FRowTitleCell.SaveToXML(XML, Path+'RowTitleCell/');
  FRowTotalCell.SaveToXML(XML, Path+'RowTotalCell/');
  FColTitleCell.SaveToXML(XML, Path+'ColTitleCell/');
  FColTotalCell.SaveToXML(XML, Path+'ColTotalCell/');
  FGrandTotalCell.SaveToXML(XML, Path+'GrandTotalCell/');

  FTotalCHCell.SaveToXML(XML, Path+'TotalCHCell/');
  FTotalRHCell.SaveToXML(XML, Path+'TotalRHCell/');
end;

procedure TlrCrossView.LoadFromStream(Stream: TStream);
begin
  inherited LoadFromStream(Stream);
  Stream.Read(FShowColumnHeader, 1); { TODO : Need use SizeOf(????) }
  Stream.Read(FShowColumnTotal, 1); { TODO : Need use SizeOf(????) }
  Stream.Read(FShowCorner, 1); { TODO : Need use SizeOf(????) }
  Stream.Read(FShowRowHeader, 1); { TODO : Need use SizeOf(????) }
  Stream.Read(FShowRowTotal, 1); { TODO : Need use SizeOf(????) }
  Stream.Read(FShowTitle, 1); { TODO : Need use SizeOf(????) }
  Stream.Read(FShowGrandTotal, 1); { TODO : Need use SizeOf(????) }
  Stream.Read(FShowTotalCHCell, 1); { TODO : Need use SizeOf(????) }
  Stream.Read(FShowTotalRHCell, 1); { TODO : Need use SizeOf(????) }

  FDataSetName:=frReadString(Stream);
  FCellFields.Text:=frReadString(Stream);
  FColumnFields.Text:=frReadString(Stream);
  FRowFields.Text:=frReadString(Stream);

  BeginUpdate;
  FDataCell.LoadFromStream(Stream);
  FRowTitleCell.LoadFromStream(Stream);
  FRowTotalCell.LoadFromStream(Stream);
  FColTitleCell.LoadFromStream(Stream);
  FColTotalCell.LoadFromStream(Stream);
  FGrandTotalCell.LoadFromStream(Stream);
  FTotalCHCell.LoadFromStream(Stream);
  FTotalRHCell.LoadFromStream(Stream);
  EndUpdate;

  FDataCell.DY:=18;
  FRowTitleCell.DY:=18;
  FRowTotalCell.DY:=18;
  FColTitleCell.DY:=18;
  FColTotalCell.DY:=18;
  FGrandTotalCell.DY:=18;
  FTotalCHCell.DY:=18;
  FTotalRHCell.DY:=18;
end;

procedure TlrCrossView.SaveToStream(Stream: TStream);
begin
  inherited SaveToStream(Stream);
  Stream.Write(FShowColumnHeader, 1);{ TODO : Need use SizeOf(????) }
  Stream.Write(FShowColumnTotal, 1); { TODO : Need use SizeOf(????) }
  Stream.Write(FShowCorner, 1);      { TODO : Need use SizeOf(????) }
  Stream.Write(FShowRowHeader, 1);   { TODO : Need use SizeOf(????) }
  Stream.Write(FShowRowTotal, 1);    { TODO : Need use SizeOf(????) }
  Stream.Write(FShowTitle, 1);       { TODO : Need use SizeOf(????) }
  Stream.Write(FShowGrandTotal, 1);  { TODO : Need use SizeOf(????) }
  Stream.Write(FShowTotalCHCell, 1); { TODO : Need use SizeOf(????) }
  Stream.Write(FShowTotalRHCell, 1); { TODO : Need use SizeOf(????) }

  frWriteString(Stream, FDataSetName);
  frWriteString(Stream, FCellFields.Text);
  frWriteString(Stream, FColumnFields.Text);
  frWriteString(Stream, FRowFields.Text);

  FDataCell.SaveToStream(Stream);
  FRowTitleCell.SaveToStream(Stream);
  FRowTotalCell.SaveToStream(Stream);
  FColTitleCell.SaveToStream(Stream);
  FColTotalCell.SaveToStream(Stream);
  FGrandTotalCell.SaveToStream(Stream);
  FTotalCHCell.SaveToStream(Stream);
  FTotalRHCell.SaveToStream(Stream);
end;

procedure InitializeCrosstAddin;
begin
  frSetAddinHint(TlrCrossView, sInsCrossTab);
end;

procedure InitCrossView;
begin
  if not assigned(lrBMPCrossView) then
  begin
    lrBMPCrossView := TBitmap.Create;
    lrBMPCrossView.LoadFromResourceName(HInstance, 'lr_crossview');
    frRegisterObject(TlrCrossView, lrBMPCrossView, '' {TlrCrossView.ClassName}, nil, otlReportView, @InitializeCrosstAddin {nil}, @lrCrossTabEditor);
  end;
end;

initialization
  InitCrossView;
finalization
  if Assigned(lrBMPCrossView) then
    FreeAndNil(lrBMPCrossView);
end.