-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDM.Db.pas
65 lines (52 loc) · 1.25 KB
/
DM.Db.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
unit DM.Db;
interface
uses
System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf,
FireDAC.DApt.Intf, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client,
System.NetEncoding.Sqids;
type
TDbModule = class(TDataModule)
tblSqids: TFDMemTable;
tblSqidsNumber: TSmallintField;
tblSqidsId: TStringField;
procedure tblSqidsCalcFields(DataSet: TDataSet);
public
procedure InitData;
procedure Refresh;
end;
var
DbModule: TDbModule;
implementation
{%CLASSGROUP 'FMX.Controls.TControl'}
{$R *.dfm}
uses
CommonU;
{ TDataModule1 }
procedure TDbModule.InitData;
begin
// We preload the memtabe with 1000 rows
tblSqids.Active := True;
tblSqids.DisableControls;
try
for var i := 0 to 999 do
begin
tblSqids.Append;
tblSqids.FieldByName('Number').AsInteger := i;
tblSqids.Post;
end;
tblSqids.First;
finally
tblSqids.EnableControls;
end;
end;
procedure TDbModule.Refresh;
begin
tblSqids.Refresh;
end;
procedure TDbModule.tblSqidsCalcFields(DataSet: TDataSet);
begin
var number := DataSet.FieldByName('Number').asString;
DataSet.FieldByName('Id').AsString := MySqids.Encode(number);
end;
end.