share.pas

来自「数据库的附加」· PAS 代码 · 共 55 行

PAS
55
字号
unit Share;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Registry, StdCtrls;
  Const
    sReg1='SYSTEM\ControlSet001\Control\ComputerName\ComputerName';
    sKey1='ComputerName';
  Type
    TShare=class
    public
      function GetRegistryValue(sPath,sKey:string): string;
      function WriteRegistryValue(sPath,sKey,sValue:string):Boolean;

    End;

implementation

function TShare.GetRegistryValue(sPath,sKey:string): string;
var
  Registry: TRegistry;
  S: string;
begin
  Registry := TRegistry.Create;
  try
    Registry.RootKey := HKEY_LOCAL_MACHINE;
    Registry.OpenKey(sPath, True);
    Result := Registry.ReadString(sKey);
  finally
    Registry.Free;
  end;
end;


function TShare.WriteRegistryValue(sPath,sKey,sValue:string):Boolean;
var
  Registry: TRegistry;
  S: string;
begin
  Registry := TRegistry.Create;
  try
    Registry.RootKey := HKEY_LOCAL_MACHINE;
    Registry.OpenKey(sPath, True);
    Registry.WriteString(sKey,sValue);
    Result := True;
  except
    Result := False;
  end;
  Registry.Free;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?