-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathDataGrabber.FieldInspector.pas
199 lines (164 loc) · 5.33 KB
/
DataGrabber.FieldInspector.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
{
Copyright (C) 2013-2025 Tim Sinaeve tim.sinaeve@gmail.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
}
{$I DataGrabber.inc}
unit DataGrabber.FieldInspector;
interface
{ A TField inspector for any given TDataSet descendant. }
uses
Winapi.Windows, Winapi.Messages,
System.SysUtils, System.Variants, System.Classes, System.Actions,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.ActnList,
Data.DB,
zObjInspector,
VirtualTrees, VirtualTrees.BaseTree;
type
TfrmFieldInspector = class(TForm)
{$REGION 'designer controls'}
aclMain : TActionList;
actInspect : TAction;
pnlLeft : TPanel;
pnlRight : TPanel;
splVertical : TSplitter;
{$ENDREGION}
procedure FVSTFieldsGetText(
Sender : TBaseVirtualTree;
Node : PVirtualNode;
Column : TColumnIndex;
TextType : TVSTTextType;
var CellText : string
);
procedure FVSTFieldsFocusChanged(
Sender : TBaseVirtualTree;
Node : PVirtualNode;
Column : TColumnIndex
);
procedure actInspectExecute(Sender: TObject);
private
FDataSet : TDataSet;
FOIField : TzObjectInspector;
FVSTFields : TVirtualStringTree;
function GetDataSet: TDataSet;
procedure SetDataSet(const Value: TDataSet);
protected
procedure UpdateActions; override;
public
constructor Create(
AOwner : TComponent;
ADataSet : TDataSet = nil
); reintroduce; virtual;
procedure UpdateView;
property DataSet : TDataSet
read GetDataSet write SetDataSet;
end;
implementation
{$R *.dfm}
uses
System.Math, System.UITypes,
VirtualTrees.Types, VirtualTrees.Header,
Spring,
DDuce.Factories.VirtualTrees, DDuce.Factories.zObjInspector,
DDuce.ObjectInspector.zObjectInspector,
DataGrabber.Resources;
{$REGION 'construction and destruction'}
constructor TfrmFieldInspector.Create(AOwner: TComponent; ADataSet: TDataSet);
var
C : TVirtualTreeColumn;
begin
inherited Create(AOwner);
FDataSet := ADataSet;
FOIField := TzObjectInspectorFactory.Create(Self, pnlRight);
FVSTFields := TVirtualStringTreeFactory.CreateGrid(Self, pnlLeft);
// cell in first column is fully selected
FVSTFields.TreeOptions.PaintOptions := // always show selection
FVSTFields.TreeOptions.PaintOptions - [toHideSelection];
FVSTFields.TreeOptions.PaintOptions := // show always as focused
FVSTFields.TreeOptions.PaintOptions + [toPopupMode];
FVSTFields.TreeOptions.SelectionOptions := // disable selection rectangle
FVSTFields.TreeOptions.SelectionOptions - [toDisableDrawSelection];
FVSTFields.TreeOptions.SelectionOptions := // show always a selected node
FVSTFields.TreeOptions.SelectionOptions + [toAlwaysSelectNode];
FVSTFields.OnGetText := FVSTFieldsGetText;
FVSTFields.OnFocusChanged := FVSTFieldsFocusChanged;
FVSTFields.LineStyle := lsSolid;
FVSTFields.Header.Font.Style := FVSTFields.Header.Font.Style + [fsBold];
// required when using it as a grid
FVSTFields.Indent := 0;
C := FVSTFields.Header.Columns.Add;
C.CaptionAlignment := taCenter;
C.Text := SFieldName;
C := FVSTFields.Header.Columns.Add;
C.CaptionAlignment := taCenter;
C.Text := SFieldClass;
C.CaptionAlignment := taCenter;
C.Alignment := taCenter;
C.Width := 120;
FVSTFields.Margins.Right := 0;
end;
{$ENDREGION}
{$REGION 'property access methods'}
function TfrmFieldInspector.GetDataSet: TDataSet;
begin
Result := FDataSet;
end;
procedure TfrmFieldInspector.SetDataSet(const Value: TDataSet);
begin
if Value <> DataSet then
begin
FDataSet := Value;
if FDataSet.FieldCount > 0 then
begin
FOIField.Component := DataSet.Fields[0];
end
else
FOIField.Component := nil;
UpdateView;
end;
end;
{$ENDREGION}
{$REGION 'action handlers'}
procedure TfrmFieldInspector.actInspectExecute(Sender: TObject);
begin
InspectObject(FVSTFields);
end;
{$ENDREGION}
{$REGION 'event handlers'}
procedure TfrmFieldInspector.FVSTFieldsFocusChanged(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex);
begin
FOIField.Component := DataSet.Fields[Node.Index];
FOIField.SelectItem(-1); // this prevents any invalid selection
end;
procedure TfrmFieldInspector.FVSTFieldsGetText(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: string);
begin
if Column = 0 then
CellText := DataSet.Fields[Node.Index].FieldName
else if Column = 1 then
CellText := DataSet.Fields[Node.Index].ClassName;
end;
{$ENDREGION}
{$REGION 'protected methods'}
procedure TfrmFieldInspector.UpdateActions;
begin
inherited UpdateActions;
//FOIField.Invalidate;
end;
{$ENDREGION}
{$REGION 'public methods'}
procedure TfrmFieldInspector.UpdateView;
begin
FVSTFields.RootNodeCount := IfThen(Assigned(DataSet), DataSet.FieldCount, 0);
end;
{$ENDREGION}
end.