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: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126:
|
unit uParameterSet;
interface
uses Classes;
type TParameterSet = class(TPersistent) public procedure LoadFromUserRegistry; procedure SaveToUserRegistry; end;
implementation
uses SysUtils, TypInfo, uRegistryTools;
procedure TParameterSet.LoadFromUserRegistry(); var iProp: Integer; PropCount: Integer; PropList: PPropList; PropInfo: PPropInfo; PropName: string; PTInfo: PTypeInfo; PTData: PTypeData; vValue: Variant; begin PTInfo:= Self.ClassInfo; PTData:= GetTypeData(PTInfo); GetMem(PropList, PTData^.PropCount * SizeOf(PPropInfo));
try TRegistryTools.OpenRegistry(); PropCount:= GetPropList(PTInfo, [tkFloat, tkInteger, tkString, tkLString, tkWString ], PropList);
for iProp:= 0 to PropCount - 1 do begin PropName:= PropList^[iProp]^.Name; PropInfo:= GetPropInfo(PTInfo, PropName);
if PropInfo <> nil then begin vValue:= TRegistryTools.ReadRegistryStringEntry(PropName); case PropInfo^.PropType^.Kind of tkFloat: SetFloatProp(Self, PropInfo, VarAsType(vValue, varDouble)); tkInteger: SetOrdProp(Self, PropInfo, VarAsType(vValue, varInteger)); tkString, tkLString, tkWString: SetStrProp(Self, PropInfo, VarAsType(vValue, varString)); end; end; end; finally FreeMem(PropList, PTData^.PropCount * SizeOf(PPropInfo)); TRegistryTools.CloseRegistry(); end; end;
procedure TParameterSet.SaveToUserRegistry(); var iProp: Integer; PropCount: Integer; PropList: PPropList; PropInfo: PPropInfo; PropName: string; PTInfo: PTypeInfo; PTData: PTypeData; vValue: Variant; begin PTInfo:= Self.ClassInfo; PTData:= GetTypeData(PTInfo); GetMem(PropList, PTData^.PropCount * SizeOf(PPropInfo));
try TRegistryTools.OpenRegistry(); PropCount:= GetPropList(PTInfo, [tkFloat, tkInteger, tkString, tkLString, tkWString ], PropList);
for iProp:= 0 to PropCount - 1 do begin PropName:= PropList^[iProp]^.Name; PropInfo:= GetPropInfo(PTInfo, PropName);
if PropInfo <> nil then begin case PropInfo^.PropType^.Kind of tkFloat: vValue:= GetFloatProp(Self, PropInfo); tkInteger: vValue:= GetOrdProp(Self, PropInfo); tkString, tkLString, tkWString: vValue:= GetStrProp(Self, PropInfo); end; TRegistryTools.WriteRegistryStringEntry(PropName, VarAsType(vValue, varString)); end; end; finally FreeMem(PropList, PTData^.PropCount * SizeOf(PPropInfo)); TRegistryTools.CloseRegistry(); end; end;
end. |