-
Notifications
You must be signed in to change notification settings - Fork 39
/
Tee.GridData.Strings.pas
146 lines (106 loc) · 4.15 KB
/
Tee.GridData.Strings.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
{*********************************************}
{ TeeGrid Software Library }
{ TStringGrid emulation data class }
{ Copyright (c) 2016-2017 by Steema Software }
{ All Rights Reserved }
{*********************************************}
unit Tee.GridData.Strings;
{$I Tee.inc}
// Force range-checking in Debug mode
{$IFOPT D+}
{$R+}
{$ENDIF}
interface
{
Two classes in this unit:
1) "Virtual Mode" data
A virtual data class for custom "Column x Row" grid using events.
Usage:
var Data : TVirtualModeData;
// Columns, Rows and optional default column width (much faster)
Data:= TVirtualModeData.Create(10,1000,60);
// Events:
Data.OnGetValue:=GetCell;
Data.OnSetValue:=SetCell;
TeeGrid1.Data:= Data;
procedure TMyForm.GetCell(Sender:TObject; const AColumn:TColumn; const ARow:Integer; var AValue:String);
procedure TMyForm.SetCell(Sender:TObject; const AColumn:TColumn; const ARow:Integer; var AValue:String);
2) "TStringGrid" emulator with TStringsData class
Derived from TVirtualModeData, maintains an internal array of strings, one for
each cell in the grid.
Usage:
var Data : TStringsData;
Data:= TStringsData.Create; // optional params: Create(5,4)
// Set size
Data.Columns:= 5;
Data.Rows:= 4;
// Set data to grid
TeeGrid1.Data:= Data;
// Set header texts
Data.Headers[1]:='Company';
// Set cell values
Data[1,1]:= 'Steema';
}
uses
{System.}Classes,
Tee.Grid.Columns, Tee.GridData, Tee.Painter;
type
TOnVirtualData=procedure(Sender:TObject;
const AColumn:TColumn;
const ARow:Integer;
var AValue:String {Variant}) of object;
TStringArray=Array of String;
{ TVirtualModeData }
TVirtualModeData=class(TVirtualData)
private
FColumns: Integer;
FRows: Integer;
IDefaultWidth : Single;
IColumns : TColumns;
IHeaders : TStringArray;
FOnSetValue,
FOnGetValue: TOnVirtualData;
function GetHeader(const Column: Integer): String;
procedure SetColumns(const Value: Integer);
procedure SetHeader(const Column: Integer; const Value: String);
procedure SetRows(const Value: Integer);
{$IFOPT R+}
procedure RangeCheck(const Column,Row: Integer);
{$ENDIF}
protected
function Empty:Boolean; override;
procedure InternalResize; virtual;
function KnownCount: Boolean; override;
public
Constructor Create(const AColumns:Integer=0; const ARows:Integer=0; const DefaultWidth:Single=0); virtual;
procedure AddColumns(const AColumns:TColumns); override;
function AsString(const AColumn:TColumn; const ARow:Integer):String; override;
function AutoWidth(const APainter:TPainter; const AColumn:TColumn):Single; override;
function Count:Integer; override;
function IndexOf(const AColumn: TColumn):Integer; inline;
procedure Load(const AColumns:TColumns); override;
procedure Resize(const AColumns,ARows:Integer);
procedure SetValue(const AColumn:TColumn; const ARow:Integer; const AText:String); override;
// properties
property ColumnList:TColumns read IColumns;
property Headers[const Column:Integer]:String read GetHeader write SetHeader;
// published
property Columns:Integer read FColumns write SetColumns default 0;
property Rows:Integer read FRows write SetRows default 0;
property OnGetValue:TOnVirtualData read FOnGetValue write FOnGetValue;
property OnSetValue:TOnVirtualData read FOnSetValue write FOnSetValue;
end;
{ TStringsData }
TStringArrays=Array of TStringArray;
TStringsData=class(TVirtualModeData)
protected
IData : TStringArrays;
function GetCell(const AColumn,ARow: Integer): String; virtual;
procedure InternalResize; override;
procedure SetCell(const AColumn,ARow: Integer; const Value: String); virtual;
public
function AsString(const AColumn:TColumn; const ARow:Integer):String; override;
procedure SetValue(const AColumn:TColumn; const ARow:Integer; const AText:String); override;
property Cells[const Column,Row:Integer]:String read GetCell write SetCell; default;
end;
implementation