-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpropertiesEngine.pas
104 lines (90 loc) · 1.99 KB
/
propertiesEngine.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
unit propertiesEngine;
interface
uses
SysUtils,
Dialogs, Forms, Graphics, Classes, Controls, StdCtrls, TypInfo, Variants,
mainLCL;
function setProperty(id: integer; prop: string; Value: variant): boolean;
function getProperty(id: integer; prop: string): variant;
function existProperty(id: integer; prop: string): boolean;
function getProperties(id: integer): string;
function getPropertyType(id: integer; prop: string): integer;
implementation
function setProperty(id: integer; prop: string; Value: variant): boolean;
var
o: TObject;
inf: PPropInfo;
begin
try
o := TObject(integer(id));
inf := TypInfo.GetPropInfo(o, prop);
if inf <> nil then
SetPropValue(o, prop, Value);
except
on E: Exception do
begin
//ShowMessage(o.ClassName);
//ShowMessage(E.Message);
Result := False;
exit;
end;
end;
Result := inf <> nil;
end;
function getProperty(id: integer; prop: string): variant;
var
o: TObject;
inf: PPropInfo;
begin
o := TObject(integer(id));
inf := TypInfo.GetPropInfo(o, prop);
if inf <> nil then
Result := GetPropValue(o, prop)
else
Result := Null;
end;
function getPropertyType(id: integer; prop: string): integer;
var
o: TObject;
inf: PPropInfo;
begin
o := TObject(integer(id));
inf := TypInfo.GetPropInfo(o, prop);
if inf <> nil then
Result := integer(inf^.PropType^.Kind)
else
Result := -1;
end;
function existProperty(id: integer; prop: string): boolean;
var
o: TObject;
inf: PPropInfo;
begin
o := TObject(integer(id));
inf := TypInfo.GetPropInfo(o, prop);
Result := inf <> nil;
end;
function getProperties(id: integer): string;
var
o: TObject;
inf: PPropInfo;
lst: PPropList;
i: integer;
res: TStrings;
begin
o := TObject(integer(id));
TypInfo.GetPropList(o, lst);
res := TStringList.Create;
i := 0;
while True do
begin
inf := lst^[i];
i := i + 1;
if inf = nil then
break;
res.Add(inf^.Name);
end;
Result := res.Text;
res.Free;
end;
end.