-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLMS.Helper.RTTI.pas
More file actions
42 lines (33 loc) · 801 Bytes
/
LMS.Helper.RTTI.pas
File metadata and controls
42 lines (33 loc) · 801 Bytes
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
unit LMS.Helper.RTTI;
interface
uses
typinfo,
System.RTTI;
function GetPropertyValue(Instance: TObject; const PropName: string): String;
implementation
uses
System.SysUtils;
var
localContext: TRttiContext;
function GetPropertyValue(Instance: TObject; const PropName: string): String;
var
Prop: TRttiProperty;
aValue: TValue;
begin
Prop := localContext.GetType(Instance.ClassType).GetProperty(PropName);
if Assigned(Prop) and Prop.IsReadable then
begin
aValue := Prop.GetValue(Instance);
case aValue.Kind of
tkUString:
result := aValue.AsString;
tkFloat:
result := FloatToStr(aValue.AsType<double>);
else
result := '';
end;
end;
// else
// raise Exception.CreateFmt('Property %s cannot be read', [PropName]);
end;
end.