| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 712 人关注过本帖
标题:用Delphi怎么实现注册表路径检查
只看楼主 加入收藏
robey
Rank: 1
等 级:新手上路
帖 子:2
专家分:5
注 册:2010-5-14
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
用Delphi怎么实现注册表路径检查
一个Edit 一个Button。在Edit中输入完整的注册表路径单击button后找到的话出现“路径有效”没找到则弹出"路径无效"。要用Delphi写。哪位大侠帮帮忙咯。谢谢了。

[ 本帖最后由 robey 于 2010-5-15 17:03 编辑 ]
搜索更多相关主题的帖子: Delphi 注册表 路径 检查 
2010-05-14 18:48
shuang200911
Rank: 5Rank: 5
等 级:职业侠客
威 望:2
帖 子:39
专家分:337
注 册:2009-11-2
收藏
得分:20 
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Registry, StdCtrls, Buttons, ImgList;

type
  TForm1 = class(TForm)
    ImageList1: TImageList;
    SpeedButton1: TSpeedButton;
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    function TestHKey(const AHKey: string): Boolean;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.TestHKey(const AHKey: string): Boolean;
var
  Reg: TRegistry;
  SourceKey: string;

  function GetRootKey(var AHKey: string): Cardinal;
  const
    cntHKEY_LOCAL_MACHINE = 'HKEY_LOCAL_MACHINE';
    cntHKEY_CLASSES_ROOT = 'HKEY_CLASSES_ROOT';
    cntHKEY_CURRENT_USER = 'HKEY_CURRENT_USER';
    cntHKEY_USERS = 'HKEY_USERS';
    cntHKEY_CURRENT_CONFIG = 'HKEY_CURRENT_CONFIG';
  var
    sRootKey: string;
  begin
    Result := 0;
    sRootKey := Copy(AHKey, 1, Pos('\', AHKey) -1);
    AHKey := Copy(AHKey, Pos('\', AHKey) +1, MaxInt);
    if sRootKey = cntHKEY_LOCAL_MACHINE then Result := HKEY_LOCAL_MACHINE;
    if sRootKey = cntHKEY_CLASSES_ROOT then Result := HKEY_CLASSES_ROOT;
    if sRootKey = cntHKEY_CURRENT_USER then Result := HKEY_CURRENT_USER;
    if sRootKey = cntHKEY_USERS then Result := HKEY_USERS;
    if sRootKey = cntHKEY_CURRENT_CONFIG then Result := HKEY_CURRENT_CONFIG;
  end;
begin
  if AHKey <> '' then
  begin
    SourceKey := AHKey;
    Reg := TRegistry.Create;
    try
      Reg.RootKey :=  GetRootKey(SourceKey);
      if Reg.RootKey = 0 then Application.MessageBox('Error Key', 'Warning', MB_OK);
      if Reg.OpenKeyReadOnly(SourceKey) then
        Application.MessageBox('路径有效', 'Warning', MB_OK)
      else
        Application.MessageBox('路径无效', 'Warning', MB_OK);
    finally
      Reg.Free;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  TestHKey(Edit1.Text);
end;

end.
2010-05-18 15:37
快速回复:用Delphi怎么实现注册表路径检查
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014721 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved