Delphi quickly reads the registry

zhaozj2021-02-08  223

File: // No need to modify vcl.file: // The structural definition may not be very good.

/main.dfmobject Form1: TForm1 Left = 192 Top = 107 Width = 544 Height = 375 Caption = 'Registry' Color = clBtnFace Font.Charset = GB2312_CHARSET Font.Color = clWindowText Font.Height = -12 Font.Name = 'Arial 'Font.Style = [] OldCreateOrder = False OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 12 object Splitter1: TSplitter Left = 209 Top = 0 Width = 3 Height = 348 Cursor = crHSplit end object TreeView1: TTreeView Left = 0 Top = 0 Width = 209 Height = 348 Align = alLeft Indent = 19 TabOrder = 0 OnChange = TreeView1Change OnExpanding = TreeView1Expanding end object ListView1: TListView Left = 212 Top = 0 Width = 324 Height = 348 Align = alClient Columns = Taborder = 1 ViewStyle = vSreport EndendFile: //main.pas

Unit main;

Interface

Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Registry, Comctrls, ExtCtrls

type TForm1 = class (TForm) Splitter1: TSplitter; TreeView1: TTreeView; ListView1: TListView; procedure FormCreate (Sender: TObject); procedure TreeView1Expanding (Sender: TObject; Node: TTreeNode; var AllowExpansion: Boolean); procedure TreeView1Change (Sender: TObject ; Node: TTreeNode); private procedure ExpandSubNode (Node: TTreeNode; Info: HKEY; Index: Integer; bRoot: Boolean = False); procedure GetKeyValue (Node: TTreeNode; var SubKey: String); {Private declarations} public {public declarations } End; type tnodemyinfo = record brootnode: boolean; bvisitor: boolean; info: hkey; index: integer;

TYPE PNODEINFO = ^ TNODEMYINFO;

Var Form1: TFORM1;

IMPLEMENTATION

{$ R * .DFM} const MaxNumber = 5; RootValue: array [0..MaxNumber] of DWord = (HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG, HKEY_DYN_DATA); RootKeyName: array [0..MaxNumber] of String = ( 'HKEY_CLASSES_ROOT', 'HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE', 'HKEY_USERS', 'HKEY_CURRENT_CONFIG', 'HKEY_DYN_DATA'); procedure TForm1.FormCreate (Sender: TObject); const MyComputer = 'my computer'; var i: Integer; RootNode, SubNode: TTreeNode; begin RootNode: = TreeView1.Items.Add (nil, MyComputer); RootNode.ImageIndex: = 1; for i: = 0 to MaxNumber do begin SubNode: = TreeView1.Items.AddChild (RootNode, RootKeyName [ I]); Subnode.ImageIndex: = 1; ExpandSubnode (Subnode, RootValue [i], i, true); End;

procedure TForm1.ExpandSubNode (Node: TTreeNode; Info: HKEY; Index: Integer; bRoot: Boolean = False); var List: TStringList; SubKey: string; Reg: TRegistry; i: Integer; P: PNodeInfo; tempNode: TTreeNode; begin NEW (P); p.Brootnode: = Broot; p.info: = info; p.index: = index; p.bvisitor: = false; node.data :=p; reg: = tregistry.create; file: / / CASE REG.ROOTKEY: = info; list: = tstringlist.create; getKeyValue (node, subkey); if reg.openkey (Subkey, false). ip.getKeyNames (List); list) To list.count-1 do begin tempnode: = TreeView1.Items.addchild (node, list.strings [i]); tempnode.imageindex: = 1; end; end; reg.closekey; reg.free; list.free; End; Procedure TFORM1.GetKeyValue (Node: ttreenode; var parentnode: ttreenode; begin if (node.level = 0) or (node.level = 1) Then EXIT; Subkey: = '/' Node .Text; parentnode: = node.parent; while (parentnode <> nil) and (parentnode.level <> 1) do begy: = '/' parentnode.text Subkey; ParentNode: = Parentn Ode.parent; end; subkey: = Subkey '/';

procedure TForm1.TreeView1Expanding (Sender: TObject; Node: TTreeNode; var AllowExpansion: Boolean); var I: integer; begin if Node.Level = 0 then Exit; if not TNodeMyInfo (Node.Data ^) bVisitored then begin Screen.Cursor. : = CRHOURGLASS; for i: = 0 to node.count-1 do (node.item [i], tnodemyinfo (node.data ^). Info, TnodeMyInfo (Node.Data ^). Index); PnodeInfo (Node.Data) . BVISTORED: = true; screen.cursor: = crdefault;

procedure TForm1.TreeView1Change (Sender: TObject; Node: TTreeNode); var Reg: TRegistry; SubString: String; List: TStringList; I: integer; Item: TListItem; DataInfo: TRegDataInfo; Value: Variant; P: String; begin if Node Listview1.items.clear; list: = tstringlist.create; reg: = tregistry.create; reg.rootkey: = TnodeMyInfo (node.data ^). Info; getKeyValue (node, substring); if Reg.openkey (Substring, False) Then Begin Reg.GetValuenames (List); list); List.Sort; for i: = 0 to list.count-1 do begin value: = 'unset key value'; reg.read reg.getDataInfo (List.Strings [I], DataInfo; Case DataInfo.regdata of rdunknown: value: = 'unknown'; rdexpandstring: value: = reg.readstring (list.Strings [i]); rdbinary: begin value: = reg. ReadbinaryData (List.Strings [i], p, datainfo.datasize; value: = p; end; rdstring: value: = reg.readstring (list.strings [i]); rdinteger: value: = reg.readinteger (list .String S [I]); END; Value: = Vartostr (Value); item: = listview1.items.add; if list.strings [i] = '' Then Item.caption: = '(default)' else item.caption : = List.strings [i]; item.subitems.add (value); end; end; reg.closekey; reg.free; list.Free; end; end;

转载请注明原文地址:https://www.9cbs.com/read-2706.html

New Post(0)