-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathData.DB.Dataset.Helper.pas
79 lines (66 loc) · 1.81 KB
/
Data.DB.Dataset.Helper.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
unit Data.DB.Dataset.Helper;
interface
USes System.Types, System.SysUtils, System.Classes, System.Variants, System.MaskUtils,
System.Generics.Collections, Data.SqlTimSt, Data.FmtBcd, Data.DBCommonTypes,Data.DB,System.TypInfo,RTTI,
VarRecUtils;
type TDatasetHelper = class Helper for Data.DB.TDataset
public
function FieldSet<T>(AFieldName: String; AValue:Variant ):TDataset; overload;
function ForEach(ACallback: TProc<TDataset>):TDataset;
function Field( AFieldName: String ):TFIeld; overload;
function InsertArrayRecords(const Values: TArray<TConstArray>):TDataset; overload;
function Append:TDataset;
function Post:TDataset;
end;
implementation
var BookMark: TBookmark;
{ TFieldHelper }
function TDatasetHelper.Append: TDataset;
begin
Result:= Self;
inherited Append;
end;
function TDatasetHelper.Field(AFieldName: String): TFIeld;
begin
Result := FieldByName(AFieldName)
end;
function TDatasetHelper.FieldSet<T>(AFieldName: String; AValue:Variant): TDataset;
begin
Result:= Self;
Field(AFieldName).Value := AValue;
end;
function TDatasetHelper.ForEach(ACallback: TProc<TDataset>): TDataset;
begin
Result := Self;
Bookmark := GetBookmark;
DisableControls;
try
First;
while not Eof do
begin
if Assigned(ACallback) then
ACallback(Self);
Next;
end;
finally
GotoBookmark(Bookmark);
EnableControls;
end;
end;
function TDatasetHelper.InsertArrayRecords(const Values: TArray<TConstArray>): TDataset;
var I: Integer;
begin
Result:= Self;
Last;
for I := Low(Values) to High(Values) do
begin
InsertRecord(Values[I]);
next;
end;
end;
function TDatasetHelper.Post: TDataset;
begin
result:= Self;
inherited post;
end;
end.