-
Notifications
You must be signed in to change notification settings - Fork 7
/
SQLG.Table.pas
49 lines (39 loc) · 1.22 KB
/
SQLG.Table.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
unit SQLG.Table;
interface
uses
System.Rtti, SQLG.Types;
type
TSQLTable = class
protected
FTableName: string;
public
property TableName: string read FTableName;
constructor Create;
end;
var
Context: TRttiContext;
implementation
uses
SQLG.Field;
{ TSQLTable }
constructor TSQLTable.Create;
begin
inherited;
var FClass := Context.GetType(Self.ClassType);
if FClass.HasAttribute(TableNameAttribute) then
FTableName := FClass.GetAttribute<TableNameAttribute>.Value;
for var FField in FClass.GetFields do
begin
if FField.HasAttribute(FieldNameAttribute) then
if FField.FieldType.IsRecord then
begin
if FField.GetValue(Self).IsType<TFInteger>(False) then
FField.SetValue(Self, TValue.From(TFInteger.Create(FTableName, FField.GetAttribute<FieldNameAttribute>.Value)))
else if FField.GetValue(Self).IsType<TFString>(False) then
FField.SetValue(Self, TValue.From(TFString.Create(FTableName, FField.GetAttribute<FieldNameAttribute>.Value)))
else if FField.GetValue(Self).IsType<TFGUID>(False) then
FField.SetValue(Self, TValue.From(TFGUID.Create(FTableName, FField.GetAttribute<FieldNameAttribute>.Value)));
end;
end;
end;
end.