Created
March 2, 2020 10:23
-
-
Save bero/12287d63adad97a2d0eec0e7b4f0c12b to your computer and use it in GitHub Desktop.
Delphi RTTI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit SystemConfigCommon; | |
type | |
TSystemConfigCommon = class | |
private | |
function GetUseBatchQueries: Boolean; | |
public | |
property UseBatchQueries: Boolean read GetUseBatchQueries; | |
end; | |
function TSystemConfigCommon.GetUseBatchQueries: Boolean; | |
begin | |
Result := Settings.ReadBool('Database', 'UseBatchQueries', True); | |
end; | |
unit frmSystemConfig; | |
procedure TSysConfigForm.ReadAllsettings; | |
var | |
vConfig: TSystemConfig; | |
vContext: TRttiContext; | |
vType: TRttiType; | |
vProperty: TRttiProperty; | |
vMethod: TRttiMethod; | |
vPropIndex: Integer; | |
vSetting: TAtIniFile; | |
i: Integer; | |
vPropArray: TArray<TRttiProperty>; | |
begin | |
vConfig := GetSystemConfig; | |
vSetting := vConfig.Settings as TATInifile; | |
vPropIndex := 0; | |
vContext := TRttiContext.Create; | |
try | |
vType := vContext.GetType(vConfig.ClassType); | |
vPropArray := vType.GetProperties; | |
for i := 0 to High(vPropArray) do | |
begin | |
vProperty := vPropArray[i]; | |
if vProperty.Name <> 'Settings' then | |
begin | |
vMethod := vType.GetMethod('Get' + vProperty.Name); | |
Assert(Assigned(vMethod), vProperty.Name + ' not found'); | |
tvAllSettings.DataController.AppendRecord; | |
tvAllSettings.DataController.Values[vPropIndex, colAllSettingValue.Index] := vMethod.Invoke(vConfig, []).ToString; // Must be read first | |
tvAllSettings.DataController.Values[vPropIndex, colSection.Index] := vSetting.SettingSection; | |
tvAllSettings.DataController.Values[vPropIndex, colAllSettingID.Index] := vSetting.SettingIdentity; | |
tvAllSettings.DataController.Values[vPropIndex, colTestSource.Index] := vSetting.SettingSource; | |
tvAllSettings.DataController.Values[vPropIndex, colAllSettingDefault.Index] := vSetting.SettingDefault; | |
Inc(vPropIndex); | |
end; | |
end; | |
finally | |
vContext.Free; | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment