/[projects]/dao/DelphiScanner/Components/tpsystools_4.04/examples/Delphi/RIEditU1.pas
ViewVC logotype

Contents of /dao/DelphiScanner/Components/tpsystools_4.04/examples/Delphi/RIEditU1.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2671 - (show annotations) (download)
Tue Aug 25 18:15:15 2015 UTC (8 years, 9 months ago) by torben
File size: 24795 byte(s)
Added tpsystools component
1 (* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is TurboPower SysTools
15 *
16 * The Initial Developer of the Original Code is
17 * TurboPower Software
18 *
19 * Portions created by the Initial Developer are Copyright (C) 1996-2002
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * ***** END LICENSE BLOCK ***** *)
25
26 unit RIEditU1;
27
28 interface
29
30 uses
31 Windows,
32 Messages,
33 Graphics,
34 Classes,
35 SysUtils,
36 Dialogs,
37 Controls,
38 Forms,
39 StdCtrls,
40 Outline,
41 ExtCtrls,
42 Buttons,
43 Menus,
44 Grids,
45
46 {$IFOPT H+}
47 STStrL,
48 {$ELSE}
49 STStrS,
50 {$ENDIF}
51 STConst,
52 STBase;
53
54 type
55 TForm1 = class(TForm)
56 Outline1: TOutline;
57 Panel1: TPanel;
58 IniFileCB: TCheckBox;
59 Label1: TLabel;
60 Edit1: TEdit;
61 CancelBtn: TBitBtn;
62 BrowseBtn: TButton;
63 OpenDialog1: TOpenDialog;
64 LoadBtn: TButton;
65 PopupMenu1: TPopupMenu;
66 DeleteAKey: TMenuItem;
67 AddKey: TMenuItem;
68 AddValue: TMenuItem;
69 ListBox1: TListBox;
70 N1: TMenuItem;
71 ListBoxMenu: TPopupMenu;
72 ModifyValue: TMenuItem;
73 RenameValue: TMenuItem;
74 DeleteValue: TMenuItem;
75 N2: TMenuItem;
76 AddItem: TMenuItem;
77 procedure CancelBtnClick(Sender: TObject);
78 procedure FormCreate(Sender: TObject);
79 procedure BrowseBtnClick(Sender: TObject);
80 procedure IniFileCBClick(Sender: TObject);
81 procedure LoadBtnClick(Sender: TObject);
82 procedure DeleteAKeyClick(Sender: TObject);
83 procedure AddKeyClick(Sender: TObject);
84 procedure AddValueClick(Sender: TObject);
85 procedure Outline1Expand(Sender: TObject; Index: Longint);
86 procedure Outline1Click(Sender: TObject);
87 procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
88 Rect: TRect; State: TOwnerDrawState);
89 procedure FormActivate(Sender: TObject);
90 procedure Outline1Collapse(Sender: TObject; Index: Longint);
91 procedure Outline1DblClick(Sender: TObject);
92 procedure DeleteValueClick(Sender: TObject);
93 procedure RenameValueClick(Sender: TObject);
94 procedure ModifyValueClick(Sender: TObject);
95 procedure ListBox1DblClick(Sender: TObject);
96 private
97 { Private declarations }
98 public
99 { Public declarations }
100
101 procedure SetBusy(Busy : Boolean);
102
103 procedure FillListBox;
104
105 procedure LoadIniFileData;
106 procedure LoadRegistryData;
107
108 procedure GetIniSectionName(var SN : string; var Index : integer);
109
110 procedure ModifyIniItem(IniItem : string);
111 procedure ModifyRegItem(RegItem : string; ModifyValue : Boolean);
112
113 procedure RenameIniItem(IniItem : string);
114 procedure RenameRegItem(RegItem : string);
115 end;
116
117 var
118 Form1: TForm1;
119
120 implementation
121
122 {$R *.DFM}
123
124 uses
125 STDate,
126 STDateSt,
127 STRegIni,
128 RIEditU2;
129
130 var
131 TC : TStRegIni;
132
133 procedure TForm1.CancelBtnClick(Sender: TObject);
134 begin
135 Close;
136 end;
137
138 procedure TForm1.FormCreate(Sender: TObject);
139 begin
140 ListBox1.Clear;
141 Outline1.Clear;
142
143 {DO NOT ERASE THE FOLLOWING SECITON - FOR INI STARTUP}
144 IniFileCB.Checked := True;
145 {End of Section}
146
147 {DO NOT ERASE THE FOLLOWING SECITON - FOR REG STARTUP}
148 {
149 IniFileCB.Checked := False;
150 Edit1.Text := 'HKEY_CLASSES_ROOT';
151 TC := TStRegIni.Create(Edit1.Text, False);
152 TC.CurSubKey := '';
153 }
154 {End of Seciton}
155
156 BrowseBtn.Enabled := IniFileCB.Checked;
157 Edit1.Enabled := IniFileCB.Checked;
158 Edit1.ReadOnly := NOT IniFileCB.Checked;
159
160 if Assigned(TC) and not TC.IsIniFile then
161 LoadRegistryData;
162 end;
163
164
165 procedure TForm1.SetBusy(Busy : Boolean);
166 begin
167 if Busy then
168 Screen.Cursor := crHourGlass
169 else
170 Screen.Cursor := crDefault;
171 end;
172
173
174 procedure TForm1.FillListBox;
175 begin
176 ListBox1.Clear;
177 ListBox1.Perform(WM_SetRedraw,0,0);
178 try
179 TC.GetValues(ListBox1.Items);
180 finally
181 ListBox1.Perform(WM_SetRedraw,1,0);
182 ListBox1.Update;
183 end;
184 end;
185
186
187 procedure TForm1.LoadIniFileData;
188 var
189 I : Integer;
190 S : string;
191 SKList : TStringList;
192
193 begin
194 SetBusy(True);
195
196 Outline1.Clear;
197 TC.CurSubKey := '';
198 SKList := TStringList.Create;
199 try
200 S := Edit1.Text;
201 I := pos('.',S);
202 if (I > 0) then
203 Delete(S,I,Length(S)-I+1);
204 I := Length(S);
205 while S[I] <> '\' do
206 Dec(I);
207 Delete(S,1,I);
208
209 Outline1.Add(0,S);
210 TC.GetSubKeys(SKList);
211 if (SKList.Count > 0) then
212 begin
213 for I := 0 to SKList.Count-1 do
214 begin
215 with Outline1 do
216 begin
217 AddChild(1,SKList[I]);
218
219 SelectedItem := GetTextItem(SKList[I]);
220 Items[SelectedItem].Expanded := False;
221 end;
222 end;
223 TC.CurSubKey := SKList[0];
224 end;
225 finally
226 SKList.Free;
227
228 Outline1.SelectedItem := 1;
229 Outline1.Refresh;
230
231 SetBusy(False);
232 end;
233 end;
234
235 procedure TForm1.Outline1Click(Sender: TObject);
236 var
237 S : string;
238 I : Integer;
239
240 begin
241 if NOT (TC.IsIniFile) then
242 begin
243 S := Outline1.Items[Outline1.SelectedItem].FullPath;
244 I := pos('=',S);
245 if I > 0 then
246 Delete(S,I,Length(S)-I+1);
247 Edit1.Text := S;
248 end;
249 end;
250
251
252 procedure TForm1.Outline1Expand(Sender: TObject; Index: Longint);
253 var
254 Idx, I, J : integer;
255
256 PriKey,
257 S,
258 HldSK,
259 SelStr : string;
260
261 SK : TStringList;
262
263 begin
264 if (TC.IsIniFile) then
265 begin
266 with Outline1 do
267 begin
268 if SelectedItem < 2 then
269 Exit
270 else begin
271 S := Items[Outline1.SelectedItem].Text;
272 TC.CurSubKey := S;
273 FillListBox;
274 end;
275 end;
276 Exit;
277 end;
278
279 ListBox1.Clear;
280 SetBusy(True);
281 HldSK := TC.CurSubKey;
282 with Outline1 do
283 begin
284 SelStr := Items[Index].FullPath;
285 if pos('HKEY_LOCAL_MACHINE',SelStr) > 0 then
286 PriKey := RIMachine
287 else if pos('HKEY_USERS',SelStr) > 0 then
288 PriKey := RIUsers
289 else if pos('HKEY_CURRENT_USER',SelStr) > 0 then
290 PriKey := RICUser
291 else if pos('HKEY_CLASSES_ROOT',SelStr) > 0 then
292 PriKey := RIRoot;
293 TC.SetPrimary(PriKey);
294
295 I := pos('\',SelStr);
296 if (I = 0) then begin
297 Edit1.Text := SelStr;
298 SetBusy(False);
299 end else
300 begin
301 SK := TStringList.Create;
302 try
303 System.Delete(SelStr,1,I);
304 TC.CurSubKey := SelStr;
305
306 FillListBox;
307 if NOT (Items[Index].HasItems) then
308 begin
309 TC.GetSubKeys(SK);
310 for J := 0 to SK.Count-1 do
311 AddChild(Index,SK[J]);
312 end else
313 begin
314 Idx := Items[Index].GetFirstChild;
315 while (Idx <> -1) do
316 begin
317 SelStr := Items[Idx].FullPath;
318 System.Delete(SelStr,1,pos('\',SelStr));
319 TC.CurSubKey := SelStr;
320 if NOT (Items[Idx].HasItems) then
321 begin
322 TC.GetSubKeys(SK);
323 for J := 0 to SK.Count-1 do
324 AddChild(Idx,SK[J]);
325 end;
326 SK.Clear;
327 Idx := Items[Index].GetNextChild(Idx);
328 end;
329 end;
330 finally
331 SK.Free;
332 TC.CurSubKey := HldSK;
333 SetBusy(False);
334 end;
335 end;
336 end;
337 Outline1.Refresh;
338 end;
339
340
341 procedure TForm1.LoadRegistryData;
342 var
343 Idx,
344 I, J, K : Integer;
345
346 TheKey,
347 PriKey : string;
348
349 ISKList,
350 SKList : TStringList;
351
352 begin
353 if not Assigned(TC) then
354 Exit;
355
356 SetBusy(True);
357 Outline1.Clear;
358 SKList := TStringList.Create;
359 try
360 Edit1.Text := 'HKEY_CLASSES_ROOT';
361 AddValue.Visible := True;
362 RenameValue.Visible := True;
363 DeleteValue.Visible := True;
364 N2.Visible := True;
365
366 for I := 1 to 4 do
367 begin
368 case I of
369 1 : begin
370 TheKey := 'HKEY_CLASSES_ROOT';
371 PriKey := RIRoot;
372 end;
373 2 : begin
374 TheKey := 'HKEY_CURRENT_USER';
375 PriKey := RICUser;
376 end;
377 3 : begin
378 TheKey := 'HKEY_LOCAL_MACHINE';
379 PriKey := RIMachine;
380 end;
381 4 : begin
382 TheKey := 'HKEY_USERS';
383 PriKey := RIUsers;
384 end;
385 end;
386 SKList.Clear;
387
388 Outline1.Add(0,TheKey);
389
390 TC.CurSubKey := '';
391 TC.SetPrimary(PriKey);
392 TC.GetSubKeys(SKList);
393
394 with Outline1 do
395 begin
396 SelectedItem := GetTextItem(TheKey);
397 for J := 0 to SKList.Count-1 do
398 begin
399 AddChild(SelectedItem,SKList[J]);
400 Idx := Items[SelectedItem].GetLastChild;
401 ISKList := TStringList.Create;
402 try
403 TC.CurSubKey := SKList[J];
404 try
405 TC.GetSubKeys(ISKList);
406 if (ISKList.Count > 0) then
407 for K := 0 to ISKList.Count-1 do
408 AddChild(Idx,ISKList[K]);
409 except
410 {In some cases, WinNT in particularl, GetSubKeys raises an
411 exception because it tries to access a key to which *no one* has
412 access. Here we throw away the exception so the outline can
413 continue being filled}
414 end;
415 finally
416 ISKList.Free;
417 end;
418 end;
419 Items[SelectedItem].Expanded := False;
420 end;
421 end;
422 finally
423 SKList.Free;
424 TC.CurSubKey := '';
425 SetBusy(False);
426 Outline1.SelectedItem := 1;
427 Outline1.Refresh;
428 end;
429 end;
430
431
432 procedure TForm1.GetIniSectionName(var SN : string; var Index : integer);
433 var
434 p : integer;
435 S : string;
436 begin
437 with Outline1 do
438 begin
439 p := SelectedItem;
440 S := Items[p].Text;
441
442 while (p > 0) AND (pos('=',S) > 0) do
443 begin
444 S := Items[p].Text;
445 if (pos('=',S) > 0) then
446 Dec(p);
447 end;
448 SN := Items[p].Text;
449 Index := p;
450 end;
451 end;
452
453
454 procedure TForm1.BrowseBtnClick(Sender: TObject);
455 begin
456 if (OpenDialog1.Execute) then
457 begin
458 Edit1.Text := OpenDialog1.FileName;
459 TC.Free;
460 TC := TStRegIni.Create(Edit1.Text,True);
461 LoadIniFileData;
462 end;
463 end;
464
465
466 procedure TForm1.IniFileCBClick(Sender: TObject);
467 begin
468 Outline1.Clear;
469 ListBox1.Clear;
470
471 BrowseBtn.Enabled := IniFileCB.Checked;
472 Edit1.Enabled := IniFileCB.Checked;
473 Edit1.ReadOnly := NOT IniFileCB.Checked;
474
475 if NOT IniFileCB.Checked then
476 begin
477 LoadBtn.Caption := '&Refresh';
478 Edit1.Text := 'HKEY_CLASSES_ROOT';
479 TC.Free;
480 TC := TStRegIni.Create(Edit1.Text,False);
481 TC.CurSubKey := '';
482 LoadRegistryData;
483 end else
484 begin
485 Edit1.Text := '';
486 LoadBtn.Caption := 'Loa&d';
487 end;
488 end;
489
490
491 procedure TForm1.LoadBtnClick(Sender: TObject);
492 begin
493 ListBox1.Clear;
494 if (IniFileCB.Checked) then
495 begin
496 if NOT FileExists(Edit1.Text) then Exit;
497 TC.Free;
498 TC := nil;
499 TC := TStRegIni.Create(Edit1.Text,True);
500 LoadIniFileData;
501 end else
502 begin
503 TC.Free;
504 TC := nil;
505 TC := TStRegIni.Create(Edit1.Text,False);
506 LoadRegistryData;
507 end;
508 end;
509
510
511 procedure TForm1.DeleteAKeyClick(Sender: TObject);
512 var
513 p,
514 Idx : Integer;
515 SK : string;
516
517 begin
518 if Outline1.SelectedItem = 0 then
519 Exit;
520 Outline1.Perform(WM_SETREDRAW,0,0);
521 try
522 if (TC.IsIniFile) then
523 begin
524 GetIniSectionName(SK,Idx);
525 TC.CurSubKey := SK;
526 end else
527 begin
528 SK := Edit1.Text;
529 p := pos('\',SK);
530 if (p = 0) then
531 begin
532 ShowMessage('Can not delete primary key');
533 Exit;
534 end;
535 Delete(SK,1,p);
536 TC.CurSubKey := SK;
537 Idx := Outline1.SelectedItem;
538 end;
539 TC.DeleteKey(SK,False);
540 Outline1.Delete(Outline1.SelectedItem);
541
542 finally
543 Outline1.Perform(WM_SETREDRAW,1,0);
544 ListBox1.Clear;
545 Outline1.Refresh;
546 end;
547 end;
548
549
550 procedure TForm1.AddKeyClick(Sender: TObject);
551 var
552 SK,
553 NewName : string;
554 begin
555 NewName := '';
556 if InputQuery('New Name','',NewName) then
557 begin
558 Outline1.Perform(WM_SETREDRAW,0,0);
559 try
560 if (TC.IsIniFile) then
561 begin
562 TC.CreateKey(NewName);
563 TC.CurSubKey := NewName;
564 with Outline1 do
565 begin
566 Add(0,NewName);
567 SelectedItem := GetTextItem(NewName);
568 end;
569 end else
570 begin
571 with Outline1 do
572 begin
573 TC.CurSubKey := '';
574 SK := Items[SelectedItem].FullPath + '\' + NewName;
575 System.Delete(SK,1,pos('\',SK));
576 TC.CreateKey(SK);
577 AddChild(SelectedItem,NewName);
578 end;
579 end;
580 finally
581 Outline1.Perform(WM_SETREDRAW,1,0);
582 Outline1.Refresh;
583 end;
584 end;
585 end;
586
587
588 procedure TForm1.AddValueClick(Sender: TObject);
589 var
590 len,
591 Code,
592 SectionIndex : integer;
593 SValue,
594 NewName : string;
595 SectionName : string;
596 TmpVal : array[1..127] of byte;
597 ADate : TStDate;
598 ATime : TStTime;
599 AFloat : Double;
600 ALongInt : LongInt;
601
602 begin
603 DataDlg.ValueName.Text := '';
604 DataDlg.IData.Text := '';
605 DataDlg.EditingState := etAll;
606
607 if (DataDlg.ShowModal = mrOK) then
608 begin
609 Outline1.Perform(WM_SETREDRAW,0,0);
610 try
611 NewName := DataDlg.ValueName.Text;
612 SValue := DataDlg.IData.Text;
613
614 if (TC.IsIniFile) then
615 begin
616 GetIniSectionName(SectionName,SectionIndex);
617 TC.CurSubKey := SectionName;
618 end else
619 begin
620 SectionName := Edit1.Text;
621 Delete(SectionName,1,pos('\',SectionName));
622 TC.CurSubKey := SectionName;
623 SectionIndex := Outline1.SelectedItem;
624 end;
625
626 case DataDlg.DataTypeRG.ItemIndex of
627 0 : begin
628 len := Length(SValue);
629 if ((len mod 2) <> 0) then
630 begin
631 if (len > 2) then
632 begin
633 Delete(SValue,len,1);
634 Dec(len);
635 end else
636 begin
637 SValue := '00';
638 len := 2;
639 end;
640 ShowMessage('String was adjusted to even number of characters');
641 end;
642 if (TC.StringToBytes(SValue, TmpVal, len div 2)) then
643 TC.WriteBinaryData(NewName, TmpVal,len div 2)
644 else
645 ShowMessage('Error converting string to Byte array');
646 end;
647 1 : begin
648 if (CompareText(SValue,LoadStr(stscTrueString)) = 0) then
649 begin
650 TC.WriteBoolean(NewName,True);
651 SValue := LoadStr(stscTrueString);
652 end else
653 begin
654 TC.WriteBoolean(NewName,False);
655 SValue := LoadStr(stscFalseString);
656 end;
657 end;
658 2 : begin
659 ADate := DateStringToStDate(InternationalDate(False),SValue, 1950);
660 if (ADate <> BadDate) then
661 TC.WriteDate(NewName,ADate)
662 else
663 ShowMessage('Invalid date or string did not match Windows short date mask');
664 end;
665 3 : begin
666 Val(SValue,ALongInt,Code);
667 if (Code = 0) then
668 TC.WriteInteger(NewName,ALongInt)
669 else
670 ShowMessage('String could not be converted to a LongInt');
671 end;
672 4 : begin
673 Val(SValue,AFloat,Code);
674 if (Code = 0) then
675 TC.WriteFloat(NewName,AFloat)
676 else
677 ShowMessage('String could not be converted to a Double');
678 end;
679 5 : begin
680 TC.WriteString(NewName,DataDlg.IData.Text);
681 SValue := DataDlg.IData.Text;
682 end;
683 6 : begin
684 SectionName := InternationalTime(True);
685 ATime := TimeStringToStTime(InternationalTime(True),SValue);
686 if (ATime <> BadTime) then
687 TC.WriteTime(NewName,ATime)
688 else
689 ShowMessage('Invalid time or string did not match Windows time mask');
690 end;
691 end;
692 finally
693 Outline1.Perform(WM_SETREDRAW,1,0);
694 FilLListBox;
695 Outline1.Refresh;
696 end;
697 end;
698 end;
699
700 procedure TForm1.DeleteValueClick(Sender: TObject);
701 var
702 p,
703 lbidx,
704 len,
705 Idx : Integer;
706
707 SK,
708 VN : string;
709 begin
710 lbidx := ListBox1.ItemIndex;
711 if (lbidx) < 0 then
712 begin
713 ShowMessage('No value selected');
714 Exit;
715 end;
716
717 VN := ListBox1.Items[lbidx];
718 p := pos('=',VN);
719 len := Length(VN);
720 System.Delete(VN,p,len-p+1);
721
722 if (TC.IsIniFile) then
723 begin
724 GetIniSectionName(SK,Idx);
725 TC.CurSubKey := SK;
726 end else
727 begin
728 SK := Edit1.Text;
729 Delete(SK,1,pos('\',SK));
730 TC.CurSubKey := SK;
731 end;
732 TC.DeleteValue(VN);
733 ListBox1.Items.Delete(lbidx);
734 end;
735
736
737 procedure TForm1.ListBox1DblClick(Sender: TObject);
738 begin
739 ModifyValueClick(Sender);
740 end;
741
742
743 procedure TForm1.ModifyValueClick(Sender: TObject);
744 var
745 Idx : Integer;
746 begin
747 Idx := ListBox1.ItemIndex;
748 if (Idx < 0) then
749 begin
750 ShowMessage('No value selected');
751 Exit;
752 end;
753
754 if (TC.IsIniFile) then
755 ModifyIniItem(ListBox1.Items[Idx])
756 else
757 ModifyRegItem(ListBox1.Items[Idx],True);
758 end;
759
760
761 procedure TForm1.ModifyIniItem(IniItem : string);
762 var
763 p,
764 len,
765 SIndex : integer;
766
767 SName,
768 NewVal,
769 ValName : string;
770
771 begin
772 p := pos('=',IniItem);
773 len := Length(IniItem);
774
775 ValName := IniItem;
776 NewVal := IniItem;
777
778 Delete(ValName,p,len-p+1);
779 Delete(NewVal,1,p);
780
781 with DataDlg do
782 begin
783 EditingState := etValue;
784 ValueName.Text := ValName;
785 IData.Text := NewVal;
786 RGIdx := 5;
787 end;
788
789 if (DataDlg.ShowModal = mrOK) then
790 begin
791 NewVal := DataDlg.IData.Text;
792
793 {test for empty value which would delete entry from section}
794 if (Length(NewVal) = 0) then
795 NewVal := ' ';
796
797 GetIniSectionName(SName,SIndex);
798 TC.CurSubKey := SName;
799
800 try
801 TC.WriteString(ValName,NewVal);
802 finally
803 FillListBox;
804 DataDlg.EditingState := etAll;
805 end;
806 end else
807 DataDlg.EditingState := etAll;
808 end;
809
810
811 procedure TForm1.ModifyRegItem(RegItem : string; ModifyValue : Boolean);
812 var
813 p,
814 len : Integer;
815
816 Size : LongInt;
817
818 DType : DWORD;
819
820 TDbl : Double;
821 BA : array[1..127] of Byte;
822
823 SKN,
824 OldName,
825 ValName,
826 NewVal : string;
827
828 begin
829 p := pos('=',RegItem);
830 ValName := RegItem;
831 Delete(ValName,p,Length(ValName)-p+1);
832 OldName := ValName;
833
834 NewVal := RegItem;
835 Delete(NewVal,1,p);
836 while pos('"',NewVal) > 0 do
837 Delete(NewVal,pos('"',NewVal),1);
838
839 SKN := Edit1.Text;
840
841 Delete(SKN,1,pos('\',SKN));
842 TC.CurSubKey := SKN;
843
844 TC.GetDataInfo(0,ValName,Size,DType);
845
846 with DataDlg do
847 begin
848 if (ModifyValue) then
849 EditingState := etValue
850 else
851 EditingState := etName;
852 ValueName.Text := ValName;
853 IData.Text := NewVal;
854 case DType of
855 REG_SZ,
856 REG_EXPAND_SZ : RGIdx := 5;
857
858 REG_DWORD : RGIdx := 3;
859
860 REG_BINARY : begin
861 case Size of
862 8 : begin
863 RGIdx := 4;
864 TDbl := TC.ReadFloat(ValName,0);
865 Str(TDbl,NewVal);
866 IData.Text := NewVal;
867 end;
868 else
869 RGIdx := 0;
870 end;
871 end;
872 end;
873 end;
874
875 if (DataDlg.ShowModal = mrOK) then
876 begin
877 ValName := DataDlg.ValueName.Text;
878 NewVal := DataDlg.IData.Text;
879 len := Length(NewVal);
880 if NOT (ModifyValue) then
881 TC.DeleteValue(OldName);
882 try
883 case DType of
884 REG_SZ,
885 REG_EXPAND_SZ : TC.WriteString(ValName,NewVal);
886
887 REG_DWORD : TC.WriteInteger(ValName,StrToInt(NewVal));
888
889 REG_BINARY : begin
890 if DataDlg.DataTypeRG.ItemIndex = 1 then
891 TC.WriteBoolean(ValName,StrToInt(NewVal) = 1);
892 if DataDlg.DataTypeRG.ItemIndex = 4 then
893 begin
894 Val(NewVal,TDbl,p);
895 if (p = 0) then
896 TC.WriteFloat(ValName,TDbl);
897 end;
898 if DataDlg.DataTypeRG.ItemIndex = 0 then
899 begin
900 TC.StringToBytes(NewVal,BA,len);
901 TC.WriteBinaryData(NewVal,BA,len div 2);
902 end;
903 end;
904
905 end;
906 finally
907 DataDlg.EditingState := etAll;
908 FillListBox;
909 end;
910 end else
911 DataDlg.EditingState := etAll;
912 end;
913
914
915 procedure TForm1.RenameValueClick(Sender: TObject);
916 var
917 Idx : Integer;
918 VN : string;
919
920 begin
921 Idx := ListBox1.ItemIndex;
922 if (Idx < 0) then
923 begin
924 ShowMessage('No value selected');
925 Exit;
926 end;
927
928 VN := ListBox1.Items[Idx];
929
930 OutLine1.Perform(WM_SETREDRAW,0,0);
931 try
932 if (TC.IsIniFile) then
933 RenameIniItem(VN)
934 else
935 RenameRegItem(VN);
936 finally
937 Outline1.Perform(WM_SETREDRAW, 1, 0);
938 Outline1.Refresh;
939 end;
940 end;
941
942 procedure TForm1.RenameIniItem(IniItem : string);
943 var
944 p, len,
945 SIndex : integer;
946
947 SName,
948 NewName,
949 OldVal,
950 ValName : string;
951
952 begin
953 ValName := IniItem;
954 p := pos('=',ValName);
955 len := Length(ValName);
956 Delete(ValName,p,len-p+1);
957 NewName := ValName;
958
959 OldVal := IniItem;
960 Delete(OldVal,1,p);
961
962 if InputQuery('Change Name Dialog',ValName,NewName) then
963 begin
964 GetIniSectionName(SName,SIndex);
965 TC.CurSubKey := SName;
966
967 TC.DeleteValue(ValName);
968 TC.WriteString(NewName,OldVal);
969
970 FillListBox;
971 end;
972 end;
973
974
975 procedure TForm1.RenameRegItem(RegItem : string);
976 begin
977 ModifyRegItem(RegItem,False);
978 end;
979
980
981 procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
982 Rect: TRect; State: TOwnerDrawState);
983 var
984 ValName,
985 IData : string;
986 Bmp : TBitMap;
987 OS1,
988 OS2,
989 len,
990 p : Integer;
991
992 begin
993 OS1 := 25;
994 OS2 := 132;
995
996 with (Control as TListBox).Canvas do
997 begin
998 FillRect(Rect);
999 Bmp := TBitMap(TListBox(Control).Items.Objects[Index]);
1000 if (Bmp <> nil) then
1001 Draw(Rect.Left+2,Rect.Top,Bmp);
1002 ValName := TListBox(Control).Items[Index];
1003 IData := ValName;
1004 len := Length(ValName);
1005 p := pos('=',ValName);
1006
1007 Delete(ValName,p,len-p+1);
1008 Delete(IData,1,p);
1009
1010 len := Length(ValName);
1011 if (len > 15) then
1012 begin
1013 Delete(ValName,16,len-15);
1014 Insert('...',ValName,15);
1015 Delete(ValName,18,1);
1016 end;
1017
1018 if (TC.IsIniFile) then
1019 begin
1020 TextOut(Rect.Left+OS1,Rect.Top+1,ValName);
1021 TextOut(Rect.Left+OS2,Rect.Top+1,IData);
1022 end else
1023 begin
1024 TextOut(Rect.Left + OS1,Rect.Top+1,ValName);
1025 TextOut(Rect.Left + OS2,Rect.Top+1,IData);
1026 end;
1027 end;
1028 end;
1029
1030 procedure TForm1.FormActivate(Sender: TObject);
1031 begin
1032 SendMessage(ListBox1.Handle,lb_SetHorizontalExtent,2500,longint(0));
1033 end;
1034
1035 procedure TForm1.Outline1Collapse(Sender: TObject; Index: Longint);
1036 var
1037 I : integer;
1038 S : string;
1039
1040 begin
1041 if (TC.IsIniFile) then
1042 begin
1043 if Outline1.SelectedItem = 1 then
1044 ListBox1.Clear;
1045 Exit;
1046 end;
1047 ListBox1.Clear;
1048 SetBusy(True);
1049
1050 S := Outline1.Items[Index].FullPath;
1051 I := System.pos('\',S);
1052 if (I = 0) then begin
1053 SetBusy(False);
1054 Exit;
1055 end;
1056
1057 System.Delete(S,1,I);
1058 TC.CurSubKey := S;
1059
1060 FillListBox;
1061 Outline1.Refresh;
1062 SetBusy(False);
1063 end;
1064
1065 procedure TForm1.Outline1DblClick(Sender: TObject);
1066 var
1067 S : string;
1068 begin
1069 if (TC.IsIniFile) then
1070 begin
1071 with Outline1 do
1072 begin
1073 if SelectedItem > 1 then
1074 begin
1075 S := Items[Outline1.SelectedItem].Text;
1076 TC.CurSubKey := S;
1077 FillListBox;
1078 end;
1079 end;
1080 end;
1081 end;
1082
1083 end.

  ViewVC Help
Powered by ViewVC 1.1.20