Changeset 539 for Registry/Demo/UFormMain.pas
- Timestamp:
- Aug 7, 2019, 12:04:53 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Registry/Demo/UFormMain.pas
r538 r539 31 31 MenuItem5: TMenuItem; 32 32 MenuItem6: TMenuItem; 33 PopupMenu 1: TPopupMenu;33 PopupMenuValue: TPopupMenu; 34 34 Splitter1: TSplitter; 35 35 StatusBar1: TStatusBar; 36 36 TreeView1: TTreeView; 37 procedure AConnectionAddExecute(Sender: TObject); 37 38 procedure AValueAddExecute(Sender: TObject); 39 procedure AValueDeleteExecute(Sender: TObject); 40 procedure AValueEditExecute(Sender: TObject); 38 41 procedure FormShow(Sender: TObject); 39 42 procedure ListView1Data(Sender: TObject; Item: TListItem); 43 procedure ListView1DblClick(Sender: TObject); 40 44 private 41 function RegValueToString( Name: string): string;45 function RegValueToString(ValueName: string): string; 42 46 procedure LoadNode(Node: TTreeNode; Key: TRegKey); 43 47 procedure ReloadTreeNode(Node: TTreeNode; Reg: TGeneralRegistry); … … 50 54 FormMain: TFormMain; 51 55 56 52 57 implementation 53 58 54 59 uses 55 UCore ;60 UCore, UFormValue; 56 61 57 62 {$R *.lfm} … … 80 85 end; 81 86 87 procedure TFormMain.ListView1DblClick(Sender: TObject); 88 begin 89 AValueEdit.Execute; 90 end; 91 82 92 procedure TFormMain.FormShow(Sender: TObject); 83 93 begin … … 86 96 end; 87 97 98 99 procedure TFormMain.AConnectionAddExecute(Sender: TObject); 100 begin 101 end; 102 103 procedure TFormMain.AValueDeleteExecute(Sender: TObject); 104 var 105 I: Integer; 106 begin 107 if MessageDlg('Delete value', 'Do you want to delete value?', mtConfirmation, 108 [mbCancel, mbOk], 0) = mrOk then begin 109 for I := ListView1.Items.Count - 1 downto 0 do 110 if ListView1.Items[I].Selected then begin 111 ListView1.Items[I].Selected := False; 112 Core.ActiveRegistry.DeleteValue(ListView1.Items[I].Caption); 113 end; 114 ReloadValues; 115 end; 116 end; 117 88 118 procedure TFormMain.AValueAddExecute(Sender: TObject); 89 begin 90 // Core.ActiveRegistry.Write; 91 end; 92 93 function TFormMain.RegValueToString(Name: string): string; 119 var 120 FormValue: TFormValue; 121 begin 122 FormValue := TFormValue.Create(nil); 123 FormValue.EditName.Text := 'New value'; 124 FormValue.EditName.Enabled := True; 125 FormValue.SetValueType(vtString); 126 if FormValue.ShowModal = mrOk then begin 127 if FormValue.GetValueType = vtString then 128 Core.ActiveRegistry.WriteString(FormValue.EditName.Text, FormValue.EditValue.Text) 129 else if FormValue.GetValueType = vtInteger then 130 Core.ActiveRegistry.WriteInteger(FormValue.EditName.Text, FormValue.SpinEditValue.Value) 131 else if FormValue.GetValueType = vtBoolean then 132 Core.ActiveRegistry.WriteBool(FormValue.EditName.Text, FormValue.CheckBoxValue.Checked) 133 else raise Exception.Create('Unsupported type ' + RegValueTypeName[TRegValueType(FormValue.ComboBoxType.ItemIndex)]); 134 ReloadValues; 135 end; 136 FormValue.Free; 137 end; 138 139 procedure TFormMain.AValueEditExecute(Sender: TObject); 140 var 141 FormValue: TFormValue; 142 ValueInfo: TRegValueInfo; 143 PrevValueType: TRegValueType; 144 begin 145 FormValue := TFormValue.Create(nil); 146 FormValue.EditName.Text := ListView1.Selected.Caption; 147 FormValue.EditName.Enabled := False; 148 Core.ActiveRegistry.GetValueInfo(ListView1.Selected.Caption, ValueInfo); 149 PrevValueType := ValueInfo.ValueType; 150 FormValue.SetValueType(ValueInfo.ValueType); 151 if PrevValueType = vtString then 152 FormValue.EditValue.Text := Core.ActiveRegistry.ReadString(ListView1.Selected.Caption) 153 else if PrevValueType = vtInteger then 154 FormValue.SpinEditValue.Value := Core.ActiveRegistry.ReadInteger(ListView1.Selected.Caption) 155 else if PrevValueType = vtBoolean then 156 FormValue.CheckBoxValue.Checked := Core.ActiveRegistry.ReadBool(ListView1.Selected.Caption); 157 if FormValue.ShowModal = mrOk then begin 158 if FormValue.GetValueType <> PrevValueType then 159 Core.ActiveRegistry.DeleteValue(FormValue.EditName.Text); 160 if FormValue.GetValueType = vtString then 161 Core.ActiveRegistry.WriteString(FormValue.EditName.Text, FormValue.EditValue.Text) 162 else if FormValue.GetValueType = vtInteger then 163 Core.ActiveRegistry.WriteInteger(FormValue.EditName.Text, FormValue.SpinEditValue.Value) 164 else if FormValue.GetValueType = vtBoolean then 165 Core.ActiveRegistry.WriteBool(FormValue.EditName.Text, FormValue.CheckBoxValue.Checked) 166 else raise Exception.Create('Unsupported type ' + RegValueTypeName[TRegValueType(FormValue.ComboBoxType.ItemIndex)]); 167 ReloadValues; 168 end; 169 FormValue.Free; 170 end; 171 172 function TFormMain.RegValueToString(ValueName: string): string; 94 173 var 95 174 ValueType: TRegValueType; … … 98 177 begin 99 178 with Core.ActiveRegistry do begin 100 ValueType := GetValueType( Name);179 ValueType := GetValueType(ValueName); 101 180 case ValueType of 102 vtBoolean: if ReadBool( Name) then Result := 'True' else Result := 'False';103 vtInteger: Result := IntToStr(ReadInteger( Name));104 vtString: Result := ReadString( Name);105 vtFloat: Result := FloatToStr(ReadFloat( Name));181 vtBoolean: if ReadBool(ValueName) then Result := 'True' else Result := 'False'; 182 vtInteger: Result := IntToStr(ReadInteger(ValueName)); 183 vtString: Result := ReadString(ValueName); 184 vtFloat: Result := FloatToStr(ReadFloat(ValueName)); 106 185 vtUnknown: Result := '?'; 107 vtText: Result := ReadString( Name);186 vtText: Result := ReadString(ValueName); 108 187 vtBinary: begin 109 SetLength(Buffer, GetValueSize( Name));110 ReadBinaryData( Name, PByte(Buffer)^, Length(Buffer));188 SetLength(Buffer, GetValueSize(ValueName)); 189 ReadBinaryData(ValueName, PByte(Buffer)^, Length(Buffer)); 111 190 Result := ''; 112 191 for I := 0 to Length(Buffer) - 1 do begin
Note:
See TracChangeset
for help on using the changeset viewer.