-
Notifications
You must be signed in to change notification settings - Fork 1
/
camatrix.pas
5057 lines (4501 loc) · 169 KB
/
camatrix.pas
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
unit caMatrix;
{$INCLUDE ca.inc}
interface
uses
// Standard Delphi units
Windows,
SysUtils,
Classes,
Math,
Clipbrd,
TypInfo,
Contnrs,
Variants,
// ca units
caClasses,
caConsts,
caUtils,
caCell,
caVector,
caExcel,
caXML,
caLog,
caMime,
caTypes;
type
EcaMatrixError = class(EcaException);
TcaGetBooleanAsStringEvent = procedure(Sender: TObject; ACol, ARow: Integer;
ABoolean: Boolean; var AString: String) of object;
TcaGetDateTimeAsStringEvent = procedure(Sender: TObject; ACol, ARow: Integer;
ADateTime: TDateTime; var AFormat, AString: String) of object;
TcaGetDoubleAsStringEvent = procedure(Sender: TObject; ACol, ARow: Integer;
ADouble: Double; var AFormat, AString: String) of object;
TcaGetExtendedAsStringEvent = procedure(Sender: TObject; ACol, ARow: Integer;
AExtended: Extended; var AFormat, AString: String) of object;
TcaGetFormulaAsStringEvent = procedure(Sender: TObject; ACol, ARow: Integer; var AString: String) of object;
TcaGetInt64AsStringEvent = procedure(Sender: TObject; ACol, ARow: Integer;
AInteger: Integer; var AFormat, AString: String) of object;
TcaGetIntegerAsStringEvent = procedure(Sender: TObject; ACol, ARow: Integer;
AInteger: Integer; var AFormat, AString: String) of object;
TcaGetMemoAsStringEvent = procedure(Sender: TObject; ACol, ARow: Integer;
AMemo: TStrings; var AString: String) of object;
TcaGetObjectAsStringEvent = procedure(Sender: TObject; ACol, ARow: Integer;
AObject: TObject; var AString: String) of object;
TcaGetSingleAsStringEvent = procedure(Sender: TObject; ACol, ARow: Integer;
ASingle: Single; var AFormat, AString: String) of object;
TcaSetCellValueEvent = procedure(Sender: TObject; ACol, ARow: Integer; const ACell: TcaCell) of object;
TcaSetBooleanEvent = procedure(Sender: TObject; ACol, ARow: Integer; const ABoolean: Boolean) of object;
TcaSetDateTimeEvent = procedure(Sender: TObject; ACol, ARow: Integer; const ADateTime: TDateTime) of object;
TcaSetDoubleEvent = procedure(Sender: TObject; ACol, ARow: Integer; const ADouble: Double) of object;
TcaSetExtendedEvent = procedure(Sender: TObject; ACol, ARow: Integer; const AExtended: Extended) of object;
TcaSetStringEvent = procedure(Sender: TObject; ACol, ARow: Integer; const AString: string) of object;
TcaSetFormulaEvent = procedure(Sender: TObject; ACol, ARow: Integer; const AFormula: string) of object;
TcaSetInt64Event = procedure(Sender: TObject; ACol, ARow: Integer; const AInt64: Int64) of object;
TcaSetIntegerEvent = procedure(Sender: TObject; ACol, ARow: Integer; const AInteger: Integer) of object;
TcaSetMemoEvent = procedure(Sender: TObject; ACol, ARow: Integer; const AMemo: TStrings) of object;
TcaSetObjectEvent = procedure(Sender: TObject; ACol, ARow: Integer; const AObject: TObject) of object;
TcaSetSingleEvent = procedure(Sender: TObject; ACol, ARow: Integer; const ASingle: Single) of object;
//----------------------------------------------------------------------------
// IcaMatrixHeader
//----------------------------------------------------------------------------
IcaMatrixHeader = interface
['{CF673266-3EF8-48B0-9FC5-5A8C80D1316B}']
// Property methods
function GetColCount: Integer;
function GetColumnNames: String;
function GetColumnType(Index: Integer): TcaCellType;
function GetMagic: String;
function GetRowCount: Integer;
procedure SetColCount(const Value: Integer);
procedure SetColumnNames(const Value: String);
procedure SetColumnType(Index: Integer; const Value: TcaCellType);
procedure SetMagic(const Value: String);
procedure SetRowCount(const Value: Integer);
// Public methods
procedure Read(Stream: TStream);
procedure Write(Stream: TStream);
// Properties
property ColCount: Integer read GetColCount write SetColCount;
property ColumnNames: String read GetColumnNames write SetColumnNames;
property ColumnTypes[ACol: Integer]: TcaCellType read GetColumnType write SetColumnType;
property Magic: String read GetMagic write SetMagic;
property RowCount: Integer read GetRowCount write SetRowCount;
end;
//----------------------------------------------------------------------------
// TcaMatrixHeader
//----------------------------------------------------------------------------
TcaMatrix = class;
TcaMatrixHeader = class(TObject)
private
// Private fields
FColCount: Integer;
FColumnNames: String;
FColumnTypes: TcaByteString;
FMagic: String;
FMatrix: TcaMatrix;
FRowCount: Integer;
// Private methods
procedure ReadColumnNames(Stream: TStream);
procedure ReadDimensions(Stream: TStream);
procedure ReadMagic(Stream: TStream);
procedure ReadString(Stream: TStream; var AString: string);
procedure WriteColumnNames(Stream: TStream);
procedure WriteDimensions(Stream: TStream);
procedure WriteMagic(Stream: TStream);
procedure WriteString(Stream: TStream; const AString: string);
public
// Create/Destroy
constructor Create(const AMatrixRef: IInterface);
destructor Destroy; override;
// Public methods
function IsValid: Boolean;
procedure Read(Stream: TStream);
procedure Write(Stream: TStream);
procedure UpdateFromMatrix;
procedure UpdateMatrix;
end;
//---------------------------------------------------------------------------
// TcaCellConverter
//---------------------------------------------------------------------------
TcaCellConverter = class(TObject)
private
FCol: Integer;
FEmptyMemo: TStrings;
FMatrix: TcaMatrix;
FRow: Integer;
// Converter property methods
function GetAsBoolean: Boolean;
function GetAsDateTime: TDateTime;
function GetAsDouble: Double;
function GetAsExtended: Extended;
function GetAsFormula: String;
function GetAsInt64: Int64;
function GetAsInteger: Integer;
function GetAsMemo: TStrings;
function GetAsObject: TObject;
function GetAsSingle: Single;
function GetAsString: String;
function GetAsVariant: Variant;
procedure SetAsBoolean(const Value: Boolean);
procedure SetAsDateTime(const Value: TDateTime);
procedure SetAsDouble(const Value: Double);
procedure SetAsExtended(const Value: Extended);
procedure SetAsFormula(const Value: String);
procedure SetAsInt64(const Value: Int64);
procedure SetAsInteger(const Value: Integer);
procedure SetAsMemo(const Value: TStrings);
procedure SetAsObject(const Value: TObject);
procedure SetAsSingle(const Value: Single);
procedure SetAsString(const Value: String);
procedure SetAsVariant(const Value: Variant);
// Private methods
function GetFormulaAsDouble(const AFormula: String): Double;
function GetFormulaAsExtended(const AFormula: String): Extended;
function GetFormulaAsInt64(const AFormula: String): Int64;
function GetFormulaAsInteger(const AFormula: String): Integer;
function GetFormulaAsSingle(const AFormula: String): Single;
procedure AddNewCell(const ACell: TcaCell; WasSelected: Boolean; IsSetting: Boolean);
procedure ReleaseOldCell(var WasSelected: Boolean);
public
constructor Create(AMatrix: TcaMatrix);
destructor Destroy; override;
// Properties
property Col: Integer read FCol write FCol;
property Row: Integer read FRow write FRow;
// Converter properties
property AsBoolean: Boolean read GetAsBoolean write SetAsBoolean;
property AsDateTime: TDateTime read GetAsDateTime write SetAsDateTime;
property AsDouble: Double read GetAsDouble write SetAsDouble;
property AsExtended: Extended read GetAsExtended write SetAsExtended;
property AsFormula: String read GetAsFormula write SetAsFormula;
property AsInteger: Integer read GetAsInteger write SetAsInteger;
property AsInt64: Int64 read GetAsInt64 write SetAsInt64;
property AsMemo: TStrings read GetAsMemo write SetAsMemo;
property AsObject: TObject read GetAsObject write SetAsObject;
property AsSingle: Single read GetAsSingle write SetAsSingle;
property AsString: String read GetAsString write SetAsString;
property AsVariant: Variant read GetAsVariant write SetAsVariant;
end;
//---------------------------------------------------------------------------
// IcaMatrix
//---------------------------------------------------------------------------
IcaMatrix = interface
['{D290F18C-9BCD-4BC2-B99D-26A4456CAC4A}']
// Property methods
function GetAutoColCount: Boolean;
function GetAutoRowCount: Boolean;
function GetCell(ACol, ARow: Integer): TcaCell;
function GetCellIsNumeric(ACol, ARow: Integer): Boolean;
function GetColCount: Integer;
function GetColumnNames: TStrings;
function GetColumnType(Index: Integer): TcaCellType;
function GetDateFormat: String;
function GetFloatFormat: String;
function GetIntegerFormat: String;
function GetMatrixCopy: TcaMatrix;
function GetName: String;
function GetOwnsObject(ACol, ARow: Integer): Boolean;
function GetRowCount: Integer;
function GetSaveUnsorted: Boolean;
function GetSortColumns: TcaIntegerVector;
function GetSortDirections: TcaIntegerVector;
function GetSorted: Boolean;
function GetStringSortCaseInsensitive: Boolean;
function GetXML: String;
function GetXMLRowContent: String;
procedure SetAutoColCount(const Value: Boolean);
procedure SetAutoRowCount(const Value: Boolean);
procedure SetCell(ACol, ARow: Integer; const Value: TcaCell);
procedure SetColCount(const Value: Integer);
procedure SetColumnNames(const Value: TStrings);
procedure SetColumnType(Index: Integer; const Value: TcaCellType);
procedure SetDateFormat(const Value: String);
procedure SetFloatFormat(const Value: String);
procedure SetIntegerFormat(const Value: String);
procedure SetName(const Value: String);
procedure SetOwnsObject(ACol, ARow: Integer; const Value: Boolean);
procedure SetRowCount(const Value: Integer);
procedure SetSaveUnsorted(const Value: Boolean);
procedure SetSorted(const Value: Boolean);
procedure SetStringSortCaseInsensitive(const Value: Boolean);
procedure SetXML(const Value: String);
// Cell access property methods
function GetBoolean(ACol, ARow: Integer): Boolean;
function GetDateTime(ACol, ARow: Integer): TDateTime;
function GetDouble(ACol, ARow: Integer): Double;
function GetExtended(ACol, ARow: Integer): Extended;
function GetFormula(ACol, ARow: Integer): String;
function GetInteger(ACol, ARow: Integer): Integer;
function GetInt64(ACol, ARow: Integer): Int64;
function GetMemo(ACol, ARow: Integer): TStrings;
function GetObject(ACol, ARow: Integer): TObject;
function GetSelected(ACol, ARow: Integer): Boolean;
function GetSingle(ACol, ARow: Integer): Single;
function GetString(ACol, ARow: Integer): String;
function GetVariant(ACol, ARow: Integer): Variant;
procedure SetBoolean(ACol, ARow: Integer; const Value: Boolean);
procedure SetDateTime(ACol, ARow: Integer; const Value: TDateTime);
procedure SetDouble(ACol, ARow: Integer; const Value: Double);
procedure SetExtended(ACol, ARow: Integer; const Value: Extended);
procedure SetFormula(ACol, ARow: Integer; const Value: String);
procedure SetInteger(ACol, ARow: Integer; const Value: Integer);
procedure SetInt64(ACol, ARow: Integer; const Value: Int64);
procedure SetMemo(ACol, ARow: Integer; const Value: TStrings);
procedure SetObject(ACol, ARow: Integer; const Value: TObject);
procedure SetSelected(ACol, ARow: Integer; const Value: Boolean);
procedure SetSingle(ACol, ARow: Integer; const Value: Single);
procedure SetString(ACol, ARow: Integer; const Value: String);
procedure SetVariant(ACol, ARow: Integer; const Value: Variant);
// Get event property methods
function GetOnGetBooleanAsString: TcaGetBooleanAsStringEvent;
function GetOnGetDateTimeAsString: TcaGetDateTimeAsStringEvent;
function GetOnGetDoubleAsString: TcaGetDoubleAsStringEvent;
function GetOnGetExtendedAsString: TcaGetExtendedAsStringEvent;
function GetOnGetFormulaAsString: TcaGetFormulaAsStringEvent;
function GetOnGetInt64AsString: TcaGetInt64AsStringEvent;
function GetOnGetIntegerAsString: TcaGetIntegerAsStringEvent;
function GetOnGetMemoAsString: TcaGetMemoAsStringEvent;
function GetOnGetObjectAsString: TcaGetObjectAsStringEvent;
function GetOnGetSingleAsString: TcaGetSingleAsStringEvent;
procedure SetOnGetBooleanAsString(const Value: TcaGetBooleanAsStringEvent);
procedure SetOnGetDateTimeAsString(const Value: TcaGetDateTimeAsStringEvent);
procedure SetOnGetDoubleAsString(const Value: TcaGetDoubleAsStringEvent);
procedure SetOnGetExtendedAsString(const Value: TcaGetExtendedAsStringEvent);
procedure SetOnGetFormulaAsString(const Value: TcaGetFormulaAsStringEvent);
procedure SetOnGetInt64AsString(const Value: TcaGetInt64AsStringEvent);
procedure SetOnGetIntegerAsString(const Value: TcaGetIntegerAsStringEvent);
procedure SetOnGetMemoAsString(const Value: TcaGetMemoAsStringEvent);
procedure SetOnGetObjectAsString(const Value: TcaGetObjectAsStringEvent);
procedure SetOnGetSingleAsString(const Value: TcaGetSingleAsStringEvent);
// Set event property methods
function GetOnSetBoolean: TcaSetBooleanEvent;
function GetOnSetCellValue: TcaSetCellValueEvent;
function GetOnSetDateTime: TcaSetDateTimeEvent;
function GetOnSetDouble: TcaSetDoubleEvent;
function GetOnSetExtended: TcaSetExtendedEvent;
function GetOnSetString: TcaSetStringEvent;
function GetOnSetFormula: TcaSetFormulaEvent;
function GetOnSetInt64: TcaSetInt64Event;
function GetOnSetInteger: TcaSetIntegerEvent;
function GetOnSetMemo: TcaSetMemoEvent;
function GetOnSetObject: TcaSetObjectEvent;
function GetOnSetSingle: TcaSetSingleEvent;
procedure SetOnSetBoolean(const Value: TcaSetBooleanEvent);
procedure SetOnSetCellValue(const Value: TcaSetCellValueEvent);
procedure SetOnSetDateTime(const Value: TcaSetDateTimeEvent);
procedure SetOnSetDouble(const Value: TcaSetDoubleEvent);
procedure SetOnSetExtended(const Value: TcaSetExtendedEvent);
procedure SetOnSetString(const Value: TcaSetStringEvent);
procedure SetOnSetFormula(const Value: TcaSetFormulaEvent);
procedure SetOnSetInt64(const Value: TcaSetInt64Event);
procedure SetOnSetInteger(const Value: TcaSetIntegerEvent);
procedure SetOnSetMemo(const Value: TcaSetMemoEvent);
procedure SetOnSetObject(const Value: TcaSetObjectEvent);
procedure SetOnSetSingle(const Value: TcaSetSingleEvent);
// Protected methods
function GetBooleanAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetDateTimeAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetDoubleAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetExtendedAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetFormulaAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetInt64AsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetIntegerAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetMemoAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetObjectAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetSingleAsString(ACol, ARow: Integer; ACell: TcaCell): String;
procedure ReleaseCell(ACol, ARow: Integer);
procedure ReleaseCells;
// Public methods
function AddCol: Integer;
function AddRow: Integer;
function AsString(ACopyColumnNames: Boolean = True): string; overload;
function AsString(AColFrom, ARowFrom, AColTo, ARowTo: Integer; ACopyColumnNames: Boolean = True): string; overload;
function FindBooleanInColumn(ABoolean: Boolean; ACol: Integer): Integer;
function FindDateTimeInColumn(ADateTime: TDateTime; ACol: Integer): Integer;
function FindDoubleInColumn(ADouble: Double; ACol: Integer): Integer;
function FindExtendedInColumn(AExtended: Extended; ACol: Integer): Integer;
function FindFormulaInColumn(const AFormula: String; ACol: Integer): Integer;
function FindInt64InColumn(AInt64: Int64; ACol: Integer): Integer;
function FindIntegerInColumn(AInteger: Integer; ACol: Integer): Integer;
function FindMemoInColumn(AMemo: TStrings; ACol: Integer): Integer;
function FindObjectInColumn(AObject: TObject; ACol: Integer): Integer;
function FindSingleInColumn(ASingle: Single; ACol: Integer): Integer;
function FindStringInColumn(const AString: String; ACol: Integer): Integer;
procedure AddCols(ACount: Integer);
procedure AddColumnNames(AColumnNames: array of string);
procedure AddFromMatrix(Source: TcaMatrix);
procedure AddRows(ACount: Integer);
procedure AddRowValues(AValues: array of Variant);
procedure AddSortColumn(const ACol: Integer; const ASortDirection: TcaSortDirection);
procedure AssignCell(Source: TcaMatrix; const SrcCol, SrcRow, ACol, ARow: Integer);
procedure Clear; overload;
procedure Clear(AColCount, ARowCount: Integer); overload;
procedure ClearCell(const ACol, ARow: Integer);
procedure ClearRow(const ARow: Integer);
procedure ClearCol(const ACol: Integer);
procedure ClearSortColumns;
procedure CopyCol(const AFromCol, AToCol: Integer);
procedure CopyRow(const AFromRow, AToRow: Integer);
procedure CopyToClipboard(ACopyColumnNames: Boolean = True); overload;
procedure CopyToClipboard(AColFrom, ARowFrom, AColTo, ARowTo: Integer; ACopyColumnNames: Boolean = True); overload;
procedure DeleteCol(const ACol: Integer);
procedure DeleteRow(const ARow: Integer);
procedure InsertCol(const ACol: Integer);
procedure InsertRow(const ARow: Integer);
procedure MoveRowDown(const ARow: Integer);
procedure MoveRowUp(const ARow: Integer);
// Fill matrix methods
procedure Fill(AValue: Boolean); overload;
procedure Fill(AValue: TDateTime); overload;
procedure Fill(AValue: Double); overload;
procedure Fill(AValue: Extended); overload;
procedure Fill(AValue: String); overload;
procedure Fill(AValue: Integer); overload;
procedure Fill(AValue: Int64); overload;
procedure Fill(AValue: TStrings); overload;
procedure Fill(AValue: TObject); overload;
procedure Fill(AValue: Single); overload;
// Fill matrix column methods
procedure FillCol(ACol: Integer; AValue: Boolean); overload;
procedure FillCol(ACol: Integer; AValue: TDateTime); overload;
procedure FillCol(ACol: Integer; AValue: Double); overload;
procedure FillCol(ACol: Integer; AValue: Extended); overload;
procedure FillCol(ACol: Integer; AValue: String); overload;
procedure FillCol(ACol: Integer; AValue: Integer); overload;
procedure FillCol(ACol: Integer; AValue: Int64); overload;
procedure FillCol(ACol: Integer; AValue: TStrings); overload;
procedure FillCol(ACol: Integer; AValue: TObject); overload;
procedure FillCol(ACol: Integer; AValue: Single); overload;
// Fill matrix row methods
procedure FillRow(ARow: Integer; AValue: Boolean); overload;
procedure FillRow(ARow: Integer; AValue: TDateTime); overload;
procedure FillRow(ARow: Integer; AValue: Double); overload;
procedure FillRow(ARow: Integer; AValue: Extended); overload;
procedure FillRow(ARow: Integer; AValue: String); overload;
procedure FillRow(ARow: Integer; AValue: Integer); overload;
procedure FillRow(ARow: Integer; AValue: Int64); overload;
procedure FillRow(ARow: Integer; AValue: TStrings); overload;
procedure FillRow(ARow: Integer; AValue: TObject); overload;
procedure FillRow(ARow: Integer; AValue: Single); overload;
procedure GetColumnAsStrings(const ACol: Integer; AStrings: TStrings); overload;
procedure GetColumnAsStrings(const ACol: Integer; AStrings: IcaStringList); overload;
// Saving and Loading
procedure LoadFromFile(const AFileName: String);
procedure LoadFromStream(Stream: TStream);
procedure LoadFromXML(const AFileName: String);
procedure SaveToExcel(const AFileName: String);
procedure SaveToFile(const AFileName: String);
procedure SaveToStream(Stream: TStream);
procedure SaveToXML(const AFileName: String);
// Matrix math
procedure AddMatrix(AMatrix: TcaMatrix; AResultMatrix: TcaMatrix = nil);
procedure DivideMatrix(AMatrix: TcaMatrix; AResultMatrix: TcaMatrix = nil);
procedure MultiplyMatrix(AMatrix: TcaMatrix; AResultMatrix: TcaMatrix = nil);
procedure SubtractMatrix(AMatrix: TcaMatrix; AResultMatrix: TcaMatrix = nil);
// Properties
property AutoColCount: Boolean read GetAutoColCount write SetAutoColCount;
property AutoRowCount: Boolean read GetAutoRowCount write SetAutoRowCount;
property Cells[ACol, ARow: Integer]: TcaCell read GetCell write SetCell;
property CellIsNumeric[ACol, ARow: Integer]: Boolean read GetCellIsNumeric;
property ColCount: Integer read GetColCount write SetColCount;
property ColumnNames: TStrings read GetColumnNames write SetColumnNames;
property ColumnTypes[ACol: Integer]: TcaCellType read GetColumnType write SetColumnType;
property DateFormat: String read GetDateFormat write SetDateFormat;
property FloatFormat: String read GetFloatFormat write SetFloatFormat;
property IntegerFormat: String read GetIntegerFormat write SetIntegerFormat;
property MatrixCopy: TcaMatrix read GetMatrixCopy;
property Name: String read GetName write SetName;
property OwnsObject[ACol, ARow: Integer]: Boolean read GetOwnsObject write SetOwnsObject;
property RowCount: Integer read GetRowCount write SetRowCount;
property SaveUnsorted: Boolean read GetSaveUnsorted write SetSaveUnsorted;
property SortColumns: TcaIntegerVector read GetSortColumns;
property SortDirections: TcaIntegerVector read GetSortDirections;
property Sorted: Boolean read GetSorted write SetSorted;
property StringSortCaseInsensitive: Boolean read GetStringSortCaseInsensitive write SetStringSortCaseInsensitive;
property XML: String read GetXML write SetXML;
property XMLRowContent: String read GetXMLRowContent;
// Cell access properties
property Booleans[ACol, ARow: Integer]: Boolean read GetBoolean write SetBoolean;
property DateTimes[ACol, ARow: Integer]: TDateTime read GetDateTime write SetDateTime;
property Doubles[ACol, ARow: Integer]: Double read GetDouble write SetDouble;
property Extendeds[ACol, ARow: Integer]: Extended read GetExtended write SetExtended;
property Formulas[ACol, ARow: Integer]: String read GetFormula write SetFormula;
property Int64s[ACol, ARow: Integer]: Int64 read GetInt64 write SetInt64;
property Integers[ACol, ARow: Integer]: Integer read GetInteger write SetInteger;
property Memos[ACol, ARow: Integer]: TStrings read GetMemo write SetMemo;
property Objects[ACol, ARow: Integer]: TObject read GetObject write SetObject;
property Selected[ACol, ARow: Integer]: Boolean read GetSelected write SetSelected;
property Singles[ACol, ARow: Integer]: Single read GetSingle write SetSingle;
property Strings[ACol, ARow: Integer]: String read GetString write SetString;
property Variants[ACol, ARow: Integer]: Variant read GetVariant write SetVariant;
// Get related Events
property OnGetBooleanAsString: TcaGetBooleanAsStringEvent read GetOnGetBooleanAsString write SetOnGetBooleanAsString;
property OnGetDateTimeAsString: TcaGetDateTimeAsStringEvent read GetOnGetDateTimeAsString write SetOnGetDateTimeAsString;
property OnGetDoubleAsString: TcaGetDoubleAsStringEvent read GetOnGetDoubleAsString write SetOnGetDoubleAsString;
property OnGetExtendedAsString: TcaGetExtendedAsStringEvent read GetOnGetExtendedAsString write SetOnGetExtendedAsString;
property OnGetFormulaAsString: TcaGetFormulaAsStringEvent read GetOnGetFormulaAsString write SetOnGetFormulaAsString;
property OnGetInt64AsString: TcaGetInt64AsStringEvent read GetOnGetInt64AsString write SetOnGetInt64AsString;
property OnGetIntegerAsString: TcaGetIntegerAsStringEvent read GetOnGetIntegerAsString write SetOnGetIntegerAsString;
property OnGetMemoAsString: TcaGetMemoAsStringEvent read GetOnGetMemoAsString write SetOnGetMemoAsString;
property OnGetObjectAsString: TcaGetObjectAsStringEvent read GetOnGetObjectAsString write SetOnGetObjectAsString;
property OnGetSingleAsString: TcaGetSingleAsStringEvent read GetOnGetSingleAsString write SetOnGetSingleAsString;
// Set related Events
property OnSetBoolean: TcaSetBooleanEvent read GetOnSetBoolean write SetOnSetBoolean;
property OnSetCellValue: TcaSetCellValueEvent read GetOnSetCellValue write SetOnSetCellValue;
property OnSetDateTime: TcaSetDateTimeEvent read GetOnSetDateTime write SetOnSetDateTime;
property OnSetDouble: TcaSetDoubleEvent read GetOnSetDouble write SetOnSetDouble;
property OnSetExtended: TcaSetExtendedEvent read GetOnSetExtended write SetOnSetExtended;
property OnSetString: TcaSetStringEvent read GetOnSetString write SetOnSetString;
property OnSetFormula: TcaSetFormulaEvent read GetOnSetFormula write SetOnSetFormula;
property OnSetInt64: TcaSetInt64Event read GetOnSetInt64 write SetOnSetInt64;
property OnSetInteger: TcaSetIntegerEvent read GetOnSetInteger write SetOnSetInteger;
property OnSetMemo: TcaSetMemoEvent read GetOnSetMemo write SetOnSetMemo;
property OnSetObject: TcaSetObjectEvent read GetOnSetObject write SetOnSetObject;
property OnSetSingle: TcaSetSingleEvent read GetOnSetSingle write SetOnSetSingle;
end;
//---------------------------------------------------------------------------
// TcaMatrix
//---------------------------------------------------------------------------
TcaMatrix = class(TcaInterfacedPersistent, IcaMatrix, IcaCloneable, IcaAssignable, IcaLoggable)
private
FAutoColCount: Boolean;
FAutoRowCount: Boolean;
FCells: IcaSparseMatrix;
FColumnNames: TStrings;
FColumnTypeIndex: Integer;
FColumnTypes: TcaByteString;
FConverter: TcaCellConverter;
FCompRow: Integer;
FDateFormat: String;
FFloatFormat: String;
FIntegerFormat: String;
FMatrixCopy: TcaMatrix;
FName: String;
FSaveUnsorted: Boolean;
FSortColumns: TcaIntegerVector;
FSortDirections: TcaIntegerVector;
FSorted: Boolean;
FStringSortCaseInsensitive: Boolean;
FSwapRow: Integer;
FXMLReadRow: Integer;
// Get events fields
FOnGetBooleanAsString: TcaGetBooleanAsStringEvent;
FOnGetDateTimeAsString: TcaGetDateTimeAsStringEvent;
FOnGetDoubleAsString: TcaGetDoubleAsStringEvent;
FOnGetExtendedAsString: TcaGetExtendedAsStringEvent;
FOnGetFormulaAsString: TcaGetFormulaAsStringEvent;
FOnGetInt64AsString: TcaGetInt64AsStringEvent;
FOnGetIntegerAsString: TcaGetIntegerAsStringEvent;
FOnGetMemoAsString: TcaGetMemoAsStringEvent;
FOnGetObjectAsString: TcaGetObjectAsStringEvent;
FOnGetSingleAsString: TcaGetSingleAsStringEvent;
// Get events fields
FOnSetBoolean: TcaSetBooleanEvent;
FOnSetCellValue: TcaSetCellValueEvent;
FOnSetDateTime: TcaSetDateTimeEvent;
FOnSetDouble: TcaSetDoubleEvent;
FOnSetExtended: TcaSetExtendedEvent;
FOnSetString: TcaSetStringEvent;
FOnSetFormula: TcaSetFormulaEvent;
FOnSetInt64: TcaSetInt64Event;
FOnSetInteger: TcaSetIntegerEvent;
FOnSetMemo: TcaSetMemoEvent;
FOnSetObject: TcaSetObjectEvent;
FOnSetSingle: TcaSetSingleEvent;
// Cell access property methods
function GetBoolean(ACol, ARow: Integer): Boolean;
function GetDateTime(ACol, ARow: Integer): TDateTime;
function GetDouble(ACol, ARow: Integer): Double;
function GetExtended(ACol, ARow: Integer): Extended;
function GetFormula(ACol, ARow: Integer): String;
function GetInt64(ACol, ARow: Integer): Int64;
function GetInteger(ACol, ARow: Integer): Integer;
function GetMemo(ACol, ARow: Integer): TStrings;
function GetObject(ACol, ARow: Integer): TObject;
function GetSelected(ACol, ARow: Integer): Boolean;
function GetSingle(ACol, ARow: Integer): Single;
function GetString(ACol, ARow: Integer): String;
function GetVariant(ACol, ARow: Integer): Variant;
procedure SetBoolean(ACol, ARow: Integer; const Value: Boolean);
procedure SetDateTime(ACol, ARow: Integer; const Value: TDateTime);
procedure SetDouble(ACol, ARow: Integer; const Value: Double);
procedure SetExtended(ACol, ARow: Integer; const Value: Extended);
procedure SetFormula(ACol, ARow: Integer; const Value: String);
procedure SetInt64(ACol, ARow: Integer; const Value: Int64);
procedure SetInteger(ACol, ARow: Integer; const Value: Integer);
procedure SetMemo(ACol, ARow: Integer; const Value: TStrings);
procedure SetObject(ACol, ARow: Integer; const Value: TObject);
procedure SetSelected(ACol, ARow: Integer; const Value: Boolean);
procedure SetSingle(ACol, ARow: Integer; const Value: Single);
procedure SetString(ACol, ARow: Integer; const Value: String);
procedure SetVariant(ACol, ARow: Integer; const Value: Variant);
// Get event property methods
function GetOnGetBooleanAsString: TcaGetBooleanAsStringEvent;
function GetOnGetDateTimeAsString: TcaGetDateTimeAsStringEvent;
function GetOnGetDoubleAsString: TcaGetDoubleAsStringEvent;
function GetOnGetExtendedAsString: TcaGetExtendedAsStringEvent;
function GetOnGetFormulaAsString: TcaGetFormulaAsStringEvent;
function GetOnGetInt64AsString: TcaGetInt64AsStringEvent;
function GetOnGetIntegerAsString: TcaGetIntegerAsStringEvent;
function GetOnGetMemoAsString: TcaGetMemoAsStringEvent;
function GetOnGetObjectAsString: TcaGetObjectAsStringEvent;
function GetOnGetSingleAsString: TcaGetSingleAsStringEvent;
procedure SetOnGetBooleanAsString(const Value: TcaGetBooleanAsStringEvent);
procedure SetOnGetDateTimeAsString(const Value: TcaGetDateTimeAsStringEvent);
procedure SetOnGetDoubleAsString(const Value: TcaGetDoubleAsStringEvent);
procedure SetOnGetExtendedAsString(const Value: TcaGetExtendedAsStringEvent);
procedure SetOnGetFormulaAsString(const Value: TcaGetFormulaAsStringEvent);
procedure SetOnGetInt64AsString(const Value: TcaGetInt64AsStringEvent);
procedure SetOnGetIntegerAsString(const Value: TcaGetIntegerAsStringEvent);
procedure SetOnGetMemoAsString(const Value: TcaGetMemoAsStringEvent);
procedure SetOnGetObjectAsString(const Value: TcaGetObjectAsStringEvent);
procedure SetOnGetSingleAsString(const Value: TcaGetSingleAsStringEvent);
// Set event property methods
function GetOnSetBoolean: TcaSetBooleanEvent;
function GetOnSetCellValue: TcaSetCellValueEvent;
function GetOnSetDateTime: TcaSetDateTimeEvent;
function GetOnSetDouble: TcaSetDoubleEvent;
function GetOnSetExtended: TcaSetExtendedEvent;
function GetOnSetString: TcaSetStringEvent;
function GetOnSetFormula: TcaSetFormulaEvent;
function GetOnSetInt64: TcaSetInt64Event;
function GetOnSetInteger: TcaSetIntegerEvent;
function GetOnSetMemo: TcaSetMemoEvent;
function GetOnSetObject: TcaSetObjectEvent;
function GetOnSetSingle: TcaSetSingleEvent;
procedure SetOnSetBoolean(const Value: TcaSetBooleanEvent);
procedure SetOnSetCellValue(const Value: TcaSetCellValueEvent);
procedure SetOnSetDateTime(const Value: TcaSetDateTimeEvent);
procedure SetOnSetDouble(const Value: TcaSetDoubleEvent);
procedure SetOnSetExtended(const Value: TcaSetExtendedEvent);
procedure SetOnSetString(const Value: TcaSetStringEvent);
procedure SetOnSetFormula(const Value: TcaSetFormulaEvent);
procedure SetOnSetInt64(const Value: TcaSetInt64Event);
procedure SetOnSetInteger(const Value: TcaSetIntegerEvent);
procedure SetOnSetMemo(const Value: TcaSetMemoEvent);
procedure SetOnSetObject(const Value: TcaSetObjectEvent);
procedure SetOnSetSingle(const Value: TcaSetSingleEvent);
// Saving and loading private methods
function LoadBooleanFromStream(Stream: TStream): Boolean;
function LoadCellTypeFromStream(Stream: TStream): TcaCellType;
function LoadDateTimeFromStream(Stream: TStream): TDateTime;
function LoadDoubleFromStream(Stream: TStream): Double;
function LoadExtendedFromStream(Stream: TStream): Extended;
function LoadFormulaFromStream(Stream: TStream): String;
function LoadIntegerFromStream(Stream: TStream): Integer;
function LoadInt64FromStream(Stream: TStream): Int64;
function LoadMemoFromStream(Stream: TStream): IcaStringList;
function LoadSingleFromStream(Stream: TStream): Single;
function LoadStringFromStream(Stream: TStream): String;
function ReadHeader(Stream: TStream): Boolean;
procedure LoadRowFromStream(ARow: Integer; Stream: TStream);
procedure SaveBooleanToStream(Cell: TcaBooleanCell; Stream: TStream);
procedure SaveCellTypeToStream(CellType: TcaCellType; Stream: TStream);
procedure SaveDateTimeToStream(Cell: TcaDateTimeCell; Stream: TStream);
procedure SaveDoubleToStream(Cell: TcaDoubleCell; Stream: TStream);
procedure SaveExtendedToStream(Cell: TcaExtendedCell; Stream: TStream);
procedure SaveFormulaToStream(Cell: TcaFormulaCell; Stream: TStream);
procedure SaveInt64ToStream(Cell: TcaInt64Cell; Stream: TStream);
procedure SaveIntegerToStream(Cell: TcaIntegerCell; Stream: TStream);
procedure SaveMemoToStream(Cell: TcaMemoCell; Stream: TStream);
procedure SaveSingleToStream(Cell: TcaSingleCell; Stream: TStream);
procedure SaveStringToStream(Cell: TcaStringCell; Stream: TStream);
procedure SaveRowToStream(ARow: Integer; Stream: TStream);
procedure WriteHeader(Stream: TStream);
// Private methods
function CellTypeStrToCellType(const ACellTypeStr: string): TcaCellType;
function CompareCells(const ACol1, ARow1, ACol2, ARow2: Integer): TcaCompareResult;
function CompareRows(const ARow1, ARow2: Integer): TcaCompareResult;
function CreateCell(ACellType: TcaCellType): TcaCell;
function CreateXmlBuilder: IcaXmlBuilder;
function GetXMLDocumentName: String;
procedure AddXMLHeader(AXmlBuilder: IcaXmlBuilder);
procedure AddXMLFooter(AXmlBuilder: IcaXmlBuilder);
procedure CheckAutoColCount(ACol: Integer);
procedure CheckAutoRowCount(ARow: Integer);
procedure CheckDimensions(AMatrix: TcaMatrix);
procedure PerformMathOperation(AOperation: TcaMathOperation; AMatrix, AResultMatrix: TcaMatrix);
procedure ResetSwapRow;
procedure SaveUnsortedMatrix;
procedure SwapRows(const ARow1, ARow2: Integer);
procedure SynchronizeColumnNames;
// XML reading private methods
function BuildXMLAttributesList(const AAttributes: String): IcaStringList;
function GetXMLColumnFromTag(const ATag: String): Integer;
procedure RunXMLReader(AXMLReader: IcaXMLReader);
procedure XMLColCountReceived(const AData: String);
procedure XMLRowCountReceived(const AData: String);
procedure XMLColumnNameReceived(const AData: String);
procedure XMLColumnTypeReceived(const AData: String);
procedure XMLDocumentNameReceived(const ATag: String);
procedure XMLEndRowReceived;
procedure XMLRowDataReceived(const ATag, AData, AAttributes: String);
// Event handlers
procedure XMLTagEvent(Sender: TObject; const ATag, AAttributes: String; ALevel: Integer);
procedure XMLEndTagEvent(Sender: TObject; const ATag: String; ALevel: Integer);
procedure XMLDataEvent(Sender: TObject; const ATag, AData, AAttributes: String; ALevel: Integer);
protected
// Property methods
function GetAutoColCount: Boolean;
function GetAutoRowCount: Boolean;
function GetCell(ACol, ARow: Integer): TcaCell;
function GetCellIsNumeric(ACol, ARow: Integer): Boolean;
function GetColCount: Integer;
function GetColumnNames: TStrings;
function GetColumnType(ACol: Integer): TcaCellType;
function GetDateFormat: String;
function GetFloatFormat: String;
function GetIntegerFormat: String;
function GetMatrixCopy: TcaMatrix;
function GetName: String;
function GetOwnsObject(ACol, ARow: Integer): Boolean;
function GetRowCount: Integer;
function GetSaveUnsorted: Boolean;
function GetSortColumns: TcaIntegerVector;
function GetSortDirections: TcaIntegerVector;
function GetSorted: Boolean;
function GetStringSortCaseInsensitive: Boolean;
function GetXML: String;
function GetXMLRowContent: String;
procedure SetAutoColCount(const Value: Boolean);
procedure SetAutoRowCount(const Value: Boolean);
procedure SetCell(ACol, ARow: Integer; const Value: TcaCell);
procedure SetColCount(const Value: Integer);
procedure SetColumnNames(const Value: TStrings);
procedure SetColumnType(ACol: Integer; const Value: TcaCellType);
procedure SetDateFormat(const Value: String);
procedure SetFloatFormat(const Value: String);
procedure SetIntegerFormat(const Value: String);
procedure SetName(const Value: String);
procedure SetOwnsObject(ACol, ARow: Integer; const Value: Boolean);
procedure SetRowCount(const Value: Integer);
procedure SetSaveUnsorted(const Value: Boolean);
procedure SetSorted(const Value: Boolean);
procedure SetStringSortCaseInsensitive(const Value: Boolean);
procedure SetXML(const Value: String);
// Protected methods
function GetBooleanAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetDateTimeAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetDoubleAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetExtendedAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetFormulaAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetInt64AsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetIntegerAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetMemoAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetObjectAsString(ACol, ARow: Integer; ACell: TcaCell): String;
function GetSingleAsString(ACol, ARow: Integer; ACell: TcaCell): String;
procedure ReleaseCell(ACol, ARow: Integer);
procedure ReleaseCells;
procedure RestoreUnsortedMatrix;
procedure Sort;
procedure SynchronizeDimensions(AMatrix: TcaMatrix); overload;
procedure SynchronizeDimensions(AMatrix: IcaMatrix); overload;
// Protected virtual methods
function CreateBooleanCell: TcaBooleanCell; virtual;
function CreateDateTimeCell: TcaDateTimeCell; virtual;
function CreateDoubleCell: TcaDoubleCell; virtual;
function CreateExtendedCell: TcaExtendedCell; virtual;
function CreateFormulaCell: TcaFormulaCell; virtual;
function CreateInt64Cell: TcaInt64Cell; virtual;
function CreateIntegerCell: TcaIntegerCell; virtual;
function CreateMemoCell: TcaMemoCell; virtual;
function CreateObjectCell: TcaObjectCell; virtual;
function CreateSingleCell: TcaSingleCell; virtual;
function CreateStringCell: TcaStringCell; virtual;
procedure DoBuildColumnNames; virtual;
// Protected cell math methods
procedure DoAddCell(AMatrix, ResultMatrix: TcaMatrix; ACol, ARow: Integer); virtual;
procedure DoDivideCell(AMatrix, ResultMatrix: TcaMatrix; ACol, ARow: Integer); virtual;
procedure DoMultiplyCell(AMatrix, ResultMatrix: TcaMatrix; ACol, ARow: Integer); virtual;
procedure DoSubtractCell(AMatrix, ResultMatrix: TcaMatrix; ACol, ARow: Integer); virtual;
// Protected cell access methods
procedure DoGetBooleanAsString(ACol, ARow: Integer; ABoolean: Boolean; var AString: String); virtual;
procedure DoGetDateTimeAsString(ACol, ARow: Integer; ADateTime: TDateTime; var AFormat, AString: String); virtual;
procedure DoGetDoubleAsString(ACol, ARow: Integer; ADouble: Double; var AFormat, AString: String); virtual;
procedure DoGetExtendedAsString(ACol, ARow: Integer; AExtended: Extended; var AFormat, AString: String); virtual;
procedure DoGetFormulaAsString(ACol, ARow: Integer; var AString: String); virtual;
procedure DoGetInt64AsString(ACol, ARow: Integer; AInt64: Int64; var AFormat, AString: String); virtual;
procedure DoGetIntegerAsString(ACol, ARow: Integer; AInteger: Integer; var AFormat, AString: String); virtual;
procedure DoGetMemoAsString(ACol, ARow: Integer; AMemo: TStrings; var AString: String); virtual;
procedure DoGetObjectAsString(ACol, ARow: Integer; AObject: TObject; var AString: String); virtual;
procedure DoGetSingleAsString(ACol, ARow: Integer; ASingle: Single; var AFormat, AString: String); virtual;
// SetCell event trigger methods
procedure DoSetCellValue(ACol, ARow: Integer; const ACell: TcaCell);
procedure DoSetBoolean(ACol, ARow: Integer; const ABoolean: Boolean);
procedure DoSetDateTime(ACol, ARow: Integer; const ADateTime: TDateTime);
procedure DoSetDouble(ACol, ARow: Integer; const ADouble: Double);
procedure DoSetExtended(ACol, ARow: Integer; const AExtended: Extended);
procedure DoSetString(ACol, ARow: Integer; const AString: string);
procedure DoSetFormula(ACol, ARow: Integer; const AFormula: string);
procedure DoSetInt64(ACol, ARow: Integer; const AInt64: Int64);
procedure DoSetInteger(ACol, ARow: Integer; const AInteger: Integer);
procedure DoSetMemo(ACol, ARow: Integer; const AMemo: TStrings);
procedure DoSetObject(ACol, ARow: Integer; const AObject: TObject);
procedure DoSetSingle(ACol, ARow: Integer; const ASingle: Single);
public
// Create/Destroy
constructor Create; overload;
constructor Create(AAutoColCount, AAutoRowCount: Boolean); overload;
constructor Create(AColCount, ARowCount: Integer); overload;
constructor Create(AXML: string); overload;
destructor Destroy; override;
// IcaLoggable
procedure SendToLog(const AMsg: String; AClearLog: Boolean = False);
// Public methods
function AddCol: Integer; virtual;
function AddRow: Integer; virtual;
function AsString(ACopyColumnNames: Boolean = True): string; overload;
function AsString(AColFrom, ARowFrom, AColTo, ARowTo: Integer; ACopyColumnNames: Boolean = True): string; overload;
function CloneAsObject: TcaInterfacedPersistent; override;
function FindBooleanInColumn(ABoolean: Boolean; ACol: Integer): Integer;
function FindDateTimeInColumn(ADateTime: TDateTime; ACol: Integer): Integer;
function FindDoubleInColumn(ADouble: Double; ACol: Integer): Integer;
function FindExtendedInColumn(AExtended: Extended; ACol: Integer): Integer;
function FindFormulaInColumn(const AFormula: String; ACol: Integer): Integer;
function FindInt64InColumn(AInt64: Int64; ACol: Integer): Integer;
function FindIntegerInColumn(AInteger: Integer; ACol: Integer): Integer;
function FindMemoInColumn(AMemo: TStrings; ACol: Integer): Integer;
function FindObjectInColumn(AObject: TObject; ACol: Integer): Integer;
function FindSingleInColumn(ASingle: Single; ACol: Integer): Integer;
function FindStringInColumn(const AString: String; ACol: Integer): Integer;
procedure AddCols(ACount: Integer);
procedure AddColumnNames(AColumnNames: array of string);
procedure AddFromMatrix(Source: TcaMatrix); virtual;
procedure AddRows(ACount: Integer);
procedure AddRowValues(AValues: array of Variant);
procedure AddSortColumn(const ACol: Integer; const ASortDirection: TcaSortDirection);
procedure Assign(Source: TPersistent); override; // VCL compatibilty
procedure AssignFromObject(Source: TPersistent); override;
procedure AssignCell(Source: TcaMatrix; const SrcCol, SrcRow, ACol, ARow: Integer);
procedure Clear; overload;
procedure Clear(AColCount, ARowCount: Integer); overload;
procedure ClearCell(const ACol, ARow: Integer);
procedure ClearCol(const ACol: Integer);
procedure ClearRow(const ARow: Integer);
procedure ClearSortColumns;
procedure CopyCol(const AFromCol, AToCol: Integer);
procedure CopyRow(const AFromRow, AToRow: Integer);
procedure CopyToClipboard(ACopyColumnNames: Boolean = True); overload;
procedure CopyToClipboard(AColFrom, ARowFrom, AColTo, ARowTo: Integer; ACopyColumnNames: Boolean = True); overload;
procedure DeleteCol(const ACol: Integer);
procedure DeleteRow(const ARow: Integer);
procedure InsertCol(const ACol: Integer);
procedure InsertRow(const ARow: Integer);
procedure MoveRowDown(const ARow: Integer);
procedure MoveRowUp(const ARow: Integer);
// Fill matrix methods
procedure Fill(AValue: Boolean); overload;
procedure Fill(AValue: TDateTime); overload;
procedure Fill(AValue: Double); overload;
procedure Fill(AValue: Extended); overload;
procedure Fill(AValue: String); overload;
procedure Fill(AValue: Integer); overload;
procedure Fill(AValue: Int64); overload;
procedure Fill(AValue: TStrings); overload;
procedure Fill(AValue: TObject); overload;
procedure Fill(AValue: Single); overload;
// Fill matrix column methods
procedure FillCol(ACol: Integer; AValue: Boolean); overload;
procedure FillCol(ACol: Integer; AValue: TDateTime); overload;
procedure FillCol(ACol: Integer; AValue: Double); overload;
procedure FillCol(ACol: Integer; AValue: Extended); overload;
procedure FillCol(ACol: Integer; AValue: String); overload;
procedure FillCol(ACol: Integer; AValue: Integer); overload;
procedure FillCol(ACol: Integer; AValue: Int64); overload;
procedure FillCol(ACol: Integer; AValue: TStrings); overload;
procedure FillCol(ACol: Integer; AValue: TObject); overload;
procedure FillCol(ACol: Integer; AValue: Single); overload;
// Fill matrix row methods
procedure FillRow(ARow: Integer; AValue: Boolean); overload;
procedure FillRow(ARow: Integer; AValue: TDateTime); overload;
procedure FillRow(ARow: Integer; AValue: Double); overload;
procedure FillRow(ARow: Integer; AValue: Extended); overload;
procedure FillRow(ARow: Integer; AValue: String); overload;
procedure FillRow(ARow: Integer; AValue: Integer); overload;
procedure FillRow(ARow: Integer; AValue: Int64); overload;
procedure FillRow(ARow: Integer; AValue: TStrings); overload;
procedure FillRow(ARow: Integer; AValue: TObject); overload;
procedure FillRow(ARow: Integer; AValue: Single); overload;
procedure GetColumnAsStrings(const ACol: Integer; AStrings: TStrings); overload;
procedure GetColumnAsStrings(const ACol: Integer; AStrings: IcaStringList); overload;
// Saving and Loading
procedure LoadFromFile(const AFileName: String);
procedure LoadFromStream(Stream: TStream);
procedure LoadFromXML(const AFileName: String);
procedure SaveToExcel(const AFileName: String);
procedure SaveToFile(const AFileName: String);
procedure SaveToStream(Stream: TStream);
procedure SaveToXML(const AFileName: String);
// Matrix math
procedure AddMatrix(AMatrix: TcaMatrix; AResultMatrix: TcaMatrix = nil);
procedure DivideMatrix(AMatrix: TcaMatrix; AResultMatrix: TcaMatrix = nil);
procedure MultiplyMatrix(AMatrix: TcaMatrix; AResultMatrix: TcaMatrix = nil);
procedure SubtractMatrix(AMatrix: TcaMatrix; AResultMatrix: TcaMatrix = nil);
// Properties
property AutoColCount: Boolean read GetAutoColCount write SetAutoColCount;
property AutoRowCount: Boolean read GetAutoRowCount write SetAutoRowCount;
property Cells[ACol, ARow: Integer]: TcaCell read GetCell write SetCell;
property CellIsNumeric[ACol, ARow: Integer]: Boolean read GetCellIsNumeric;
property ColCount: Integer read GetColCount write SetColCount;
property ColumnNames: TStrings read GetColumnNames write SetColumnNames;
property ColumnTypes[ACol: Integer]: TcaCellType read GetColumnType write SetColumnType;
property DateFormat: String read GetDateFormat write SetDateFormat;
property FloatFormat: String read GetFloatFormat write SetFloatFormat;
property IntegerFormat: String read GetIntegerFormat write SetIntegerFormat;
property MatrixCopy: TcaMatrix read GetMatrixCopy;
property Name: String read GetName write SetName;
property OwnsObject[ACol, ARow: Integer]: Boolean read GetOwnsObject write SetOwnsObject;
property RowCount: Integer read GetRowCount write SetRowCount;
property SaveUnsorted: Boolean read GetSaveUnsorted write SetSaveUnsorted;
property SortColumns: TcaIntegerVector read GetSortColumns;
property SortDirections: TcaIntegerVector read GetSortDirections;
property Sorted: Boolean read GetSorted write SetSorted;
property StringSortCaseInsensitive: Boolean read GetStringSortCaseInsensitive write SetStringSortCaseInsensitive;
property XML: String read GetXML write SetXML;
property XMLRowContent: String read GetXMLRowContent;
// Cell access properties
property Booleans[ACol, ARow: Integer]: Boolean read GetBoolean write SetBoolean;
property DateTimes[ACol, ARow: Integer]: TDateTime read GetDateTime write SetDateTime;
property Doubles[ACol, ARow: Integer]: Double read GetDouble write SetDouble;
property Extendeds[ACol, ARow: Integer]: Extended read GetExtended write SetExtended;
property Formulas[ACol, ARow: Integer]: String read GetFormula write SetFormula;
property Integers[ACol, ARow: Integer]: Integer read GetInteger write SetInteger;
property Int64s[ACol, ARow: Integer]: Int64 read GetInt64 write SetInt64;
property Memos[ACol, ARow: Integer]: TStrings read GetMemo write SetMemo;
property Objects[ACol, ARow: Integer]: TObject read GetObject write SetObject;
property Selected[ACol, ARow: Integer]: Boolean read GetSelected write SetSelected;
property Singles[ACol, ARow: Integer]: Single read GetSingle write SetSingle;
property Strings[ACol, ARow: Integer]: String read GetString write SetString;
property Variants[ACol, ARow: Integer]: Variant read GetVariant write SetVariant;
// Get related events
property OnGetBooleanAsString: TcaGetBooleanAsStringEvent read GetOnGetBooleanAsString write SetOnGetBooleanAsString;
property OnGetDateTimeAsString: TcaGetDateTimeAsStringEvent read GetOnGetDateTimeAsString write SetOnGetDateTimeAsString;
property OnGetDoubleAsString: TcaGetDoubleAsStringEvent read GetOnGetDoubleAsString write SetOnGetDoubleAsString;
property OnGetExtendedAsString: TcaGetExtendedAsStringEvent read GetOnGetExtendedAsString write SetOnGetExtendedAsString;
property OnGetFormulaAsString: TcaGetFormulaAsStringEvent read GetOnGetFormulaAsString write SetOnGetFormulaAsString;
property OnGetInt64AsString: TcaGetInt64AsStringEvent read GetOnGetInt64AsString write SetOnGetInt64AsString;
property OnGetIntegerAsString: TcaGetIntegerAsStringEvent read GetOnGetIntegerAsString write SetOnGetIntegerAsString;
property OnGetMemoAsString: TcaGetMemoAsStringEvent read GetOnGetMemoAsString write SetOnGetMemoAsString;
property OnGetObjectAsString: TcaGetObjectAsStringEvent read GetOnGetObjectAsString write SetOnGetObjectAsString;
property OnGetSingleAsString: TcaGetSingleAsStringEvent read GetOnGetSingleAsString write SetOnGetSingleAsString;
// Set related events
property OnSetBoolean: TcaSetBooleanEvent read GetOnSetBoolean write SetOnSetBoolean;
property OnSetCellValue: TcaSetCellValueEvent read GetOnSetCellValue write SetOnSetCellValue;
property OnSetDateTime: TcaSetDateTimeEvent read GetOnSetDateTime write SetOnSetDateTime;
property OnSetDouble: TcaSetDoubleEvent read GetOnSetDouble write SetOnSetDouble;
property OnSetExtended: TcaSetExtendedEvent read GetOnSetExtended write SetOnSetExtended;
property OnSetString: TcaSetStringEvent read GetOnSetString write SetOnSetString;
property OnSetFormula: TcaSetFormulaEvent read GetOnSetFormula write SetOnSetFormula;
property OnSetInt64: TcaSetInt64Event read GetOnSetInt64 write SetOnSetInt64;
property OnSetInteger: TcaSetIntegerEvent read GetOnSetInteger write SetOnSetInteger;
property OnSetMemo: TcaSetMemoEvent read GetOnSetMemo write SetOnSetMemo;
property OnSetObject: TcaSetObjectEvent read GetOnSetObject write SetOnSetObject;
property OnSetSingle: TcaSetSingleEvent read GetOnSetSingle write SetOnSetSingle;
end;
//---------------------------------------------------------------------------
// IcaBooleanMatrix
//---------------------------------------------------------------------------
IcaBooleanMatrix = interface(IcaMatrix)
['{71D3136E-C690-46E2-950D-007F466369BC}']
property Booleans[ACol, ARow: Integer]: Boolean read GetBoolean write SetBoolean; default;
end;
//---------------------------------------------------------------------------
// TcaBooleanMatrix
//---------------------------------------------------------------------------
TcaBooleanMatrix = class(TcaMatrix, IcaBooleanMatrix)
private
function GetBoolean(ACol, ARow: Integer): Boolean;
procedure SetBoolean(ACol, ARow: Integer; const Value: Boolean);
public
property Booleans[ACol, ARow: Integer]: Boolean read GetBoolean write SetBoolean; default;
end;
//---------------------------------------------------------------------------
// IcaDateTimeMatrix
//---------------------------------------------------------------------------
IcaDateTimeMatrix = interface(IcaMatrix)
['{575FA229-78BF-458B-AA90-6371B810B931}']
property DateTimes[ACol, ARow: Integer]: TDateTime read GetDateTime write SetDateTime; default;
end;
//---------------------------------------------------------------------------
// TcaDateTimeMatrix
//---------------------------------------------------------------------------
TcaDateTimeMatrix = class(TcaMatrix, IcaDateTimeMatrix)
private
function GetDateTime(ACol, ARow: Integer): TDateTime;
procedure SetDateTime(ACol, ARow: Integer; const Value: TDateTime);
protected
procedure DoAddCell(AMatrix, ResultMatrix: TcaMatrix; ACol, ARow: Integer); override;
procedure DoDivideCell(AMatrix, ResultMatrix: TcaMatrix; ACol, ARow: Integer); override;
procedure DoMultiplyCell(AMatrix, ResultMatrix: TcaMatrix; ACol, ARow: Integer); override;
procedure DoSubtractCell(AMatrix, ResultMatrix: TcaMatrix; ACol, ARow: Integer); override;
public
property DateTimes[ACol, ARow: Integer]: TDateTime read GetDateTime write SetDateTime; default;
end;
//---------------------------------------------------------------------------
// IcaDoubleMatrix
//---------------------------------------------------------------------------
IcaDoubleMatrix = interface(IcaMatrix)
['{4943F0C1-92AB-4523-9BE8-F5E3F98F9D33}']
function GetColTotal(ACol: Integer): Double;
function GetRowTotal(ARow: Integer): Double;
// Properties
property ColTotal[ACol: Integer]: Double read GetColTotal;
property Doubles[ACol, ARow: Integer]: Double read GetDouble write SetDouble; default;
property RowTotal[ARow: Integer]: Double read GetRowTotal;
end;
//---------------------------------------------------------------------------
// TcaDoubleMatrix
//---------------------------------------------------------------------------