-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDW.VCL.DBControl.pas
131 lines (114 loc) · 3.06 KB
/
DW.VCL.DBControl.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
unit DW.VCL.DBControl;
interface
uses
Classes, System.SysUtils, DW.VCL.Control, DB, DWElementTag, DW.VCL.DataLink;
type
// Base class for DW data aware controls
TDWCustomDbControl = class(TDWInputControl)
private
FMaxLength: Integer;
procedure SetMaxLength(const AValue: Integer);
protected
FDataLink: TDWDataLink;
FDataField: string;
FDataSource: TDataSource;
procedure CheckData; virtual;
procedure Notification(AComponent: TComponent; AOperation: TOperation); override;
procedure SetDataField(const AValue: string); virtual;
procedure SetDataSource(const Value: TDataSource); virtual;
property MaxLength: Integer read FMaxLength write SetMaxLength;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure InternalRenderCss(var ACss: string); override;
function RenderAsync: TDWElementXHTMLTag; override;
function RenderHTML: TDWElementTag; override;
published
property DataSource: TDataSource read FDataSource write SetDataSource;
property DataField: string read FDataField write SetDataField;
end;
implementation
uses
DWUtils;
{ TIWBSCustomDbControl }
procedure TDWCustomDbControl.CheckData;
begin
//
end;
constructor TDWCustomDbControl.Create(AOwner: TComponent);
begin
inherited;
FDataLink := nil;
FDataField := '';
end;
destructor TDWCustomDbControl.Destroy;
begin
FreeAndNil(FDataLink);
inherited;
end;
procedure TDWCustomDbControl.InternalRenderCss(var ACss: string);
begin
inherited;
end;
procedure TDWCustomDbControl.Notification(AComponent: TComponent; AOperation: TOperation);
begin
inherited Notification(AComponent, AOperation);
if AOperation = opRemove then
if FDataSource = AComponent then
SetDataSource(nil);
end;
function TDWCustomDbControl.RenderAsync: TDWElementXHTMLTag;
begin
CheckData;
Result := inherited;
end;
function TDWCustomDbControl.RenderHTML: TDWElementTag;
begin
CheckData;
Result := inherited;
end;
procedure TDWCustomDbControl.SetDataField(const AValue: string);
var
xFld: TField;
begin
if not SameText(AValue, FDataField) then
begin
FDataField := AValue;
MaxLength := 0;
if FDataField <> '' then
begin
xFld := GetDataSourceField(FDataSource, FDataField);
if Assigned(xFld) and (xFld is TStringField) then
MaxLength := TStringField(xFld).Size;
end;
Invalidate;
end;
end;
procedure TDWCustomDbControl.SetDataSource(const Value: TDataSource);
begin
if Value <> FDataSource then
begin
FDataSource := Value;
if Value = nil then
begin
FDataField := '';
FreeAndNil(FDataLink);
end
else
begin
if FDataLink = nil then
FDataLink := TDWDataLink.Create(Self);
FDataLink.DataSource := FDataSource;
end;
Invalidate;
end;
end;
procedure TDWCustomDbControl.SetMaxLength(const AValue: Integer);
begin
if FMaxLength <> AValue then
begin
FMaxLength := AValue;
AsyncRefreshControl;
end;
end;
end.