⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dws2reginimodule.pas

📁 script language
💻 PAS
字号:
unit dws2RegIniModule;

interface
uses Classes, dws2Comp, dws2Exprs;

{ type
    TRootKey = (rkClassesRoot, rkCurrentUser, rkLocalMachine, rkUsers, rkCurrentConfig,
                rkDynData);
    TRegIniFile = class
      constructor Create(Key: string; Root: TRootKey);
      destructor Destroy; override;
      function ReadString(Section, Ident, Default: string): string;
      procedure WriteString(Section, Ident, Value: string);
      procedure EraseSection(Section: string);
      procedure DeleteKey(Section, Ident: string);
      procedure UpdateKey;
      function SectionExists(Section: string): Boolean;
      function ValueExists(Section, Ident: string): Boolean;
      procedure ReadSection(Section: string; Strings: TStringList);
      procedure ReadSections(Strings: TStringList);
      procedure ReadSectionValues(Section: String; Strings: TStringList);
      function ReadInteger(Section, Indent: string; Default: Integer): Integer;
      procedure WriteInteger(Section, Ident: string; Value: Integer);
      function ReadBool(Section, Ident: string; Default: Boolean): Boolean;
      procedure WriteBool(Section, Ident: string; Value: Boolean);
      function ReadFloat(Section, Ident: string; Default: Float): Float;
      procedure WriteFloat(Section, Ident: string; Value: Float);
      function ReadDate(Section, Ident: string; Default: DateTime): DateTime;
      procedure WriteDate(Section, Ident: string; Value: DateTime);
      function ReadTime(Section, Ident: string; Default: DateTime): DateTime;
      procedure WriteTime(Section, Ident: string; Value: DateTime);
      function ReadDateTime(Section, Ident: string; Default: DateTime): DateTime;
      procedure WriteDateTime(Section, Ident: string; Value: DateTime);
  }

type
  Tdws2RegIniLib = class(TDataModule)
    RegIniUnit: Tdws2Unit;
    procedure SetScript(const Value: TDelphiWebScriptII);
    procedure ConstructorsCreateAssignExternalObject(Info: TProgramInfo; var ExtObject: TObject);
    procedure ReadStringEval(Info: TProgramInfo; ExtObject: TObject);
    procedure WriteStringEval(Info: TProgramInfo; ExtObject: TObject);
    procedure EraseSectionEval(Info: TProgramInfo; ExtObject: TObject);
    procedure DeleteKeyEval(Info: TProgramInfo; ExtObject: TObject);
    procedure UpdateFileEval(Info: TProgramInfo; ExtObject: TObject);
    procedure SectionExistsEval(Info: TProgramInfo; ExtObject: TObject);
    procedure ReadIntegerEval(Info: TProgramInfo; ExtObject: TObject);
    procedure WriteIntegerEval(Info: TProgramInfo; ExtObject: TObject);
    procedure ReadBoolEval(Info: TProgramInfo; ExtObject: TObject);
    procedure WriteBoolEval(Info: TProgramInfo; ExtObject: TObject);
    procedure ReadDateEval(Info: TProgramInfo; ExtObject: TObject);
    procedure WriteDateEval(Info: TProgramInfo; ExtObject: TObject);
    procedure ReadTimeEval(Info: TProgramInfo; ExtObject: TObject);
    procedure WriteTimeEval(Info: TProgramInfo; ExtObject: TObject);
    procedure ReadDateTimeEval(Info: TProgramInfo; ExtObject: TObject);
    procedure WriteDateTimeEval(Info: TProgramInfo; ExtObject: TObject);
    procedure ReadFloatEval(Info: TProgramInfo; ExtObject: TObject);
    procedure WriteFloatEval(Info: TProgramInfo; ExtObject: TObject);
    procedure ValueExistsEval(Info: TProgramInfo; ExtObject: TObject);
    procedure ReadSectionEval(Info: TProgramInfo; ExtObject: TObject);
    procedure ReadSectionsEval(Info: TProgramInfo; ExtObject: TObject);
    procedure ReadSectionValuesEval(Info: TProgramInfo; ExtObject: TObject);
    procedure DestructEval(Info: TProgramInfo; ExtObject: TObject);
  private
    FScript: TDelphiWebScriptII;
  protected
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  published
    property Script: TDelphiWebScriptII read FScript write SetScript;
  end;

procedure Register;

implementation
uses Registry, Windows, dws2Symbols;

{$R *.dfm}

procedure Register;
begin
  RegisterComponents('DWS2', [Tdws2RegIniLib]);
end;

{ Tdws2RegIni }

procedure Tdws2RegIniLib.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited;
  if (Operation = opRemove) and (AComponent = Script) then
    SetScript(nil)
end;

procedure Tdws2RegIniLib.SetScript(const Value: TDelphiWebScriptII);
var
  x: Integer;
begin
  if Assigned(FScript) then
    FScript.RemoveFreeNotification(Self);
  if Assigned(Value) then
    Value.FreeNotification(Self);

  FScript := Value;
  for x := 0 to ComponentCount - 1 do
    if Components[x] is Tdws2Unit then
      Tdws2Unit(Components[x]).Script := Value;
end;

procedure Tdws2RegIniLib.ConstructorsCreateAssignExternalObject;
begin
  ExtObject := TRegistryIniFile.Create(String(Info['FileName']));
  With TRegistryIniFile(ExtObject).RegIniFile Do
    Case Integer(Info['Rootkey']) of
      0 : RootKey := HKEY_CLASSES_ROOT;
      1 : RootKey := HKEY_CURRENT_USER;
      2 : RootKey := HKEY_LOCAL_MACHINE;
      3 : RootKey := HKEY_USERS;
      4 : RootKey := HKEY_PERFORMANCE_DATA;
      5 : RootKey := HKEY_CURRENT_CONFIG;
      6 : RootKey := HKEY_DYN_DATA;
    Else
      RootKey := HKEY_CURRENT_USER;
    end;
end;

procedure Tdws2RegIniLib.ReadStringEval;
begin
  Info['Result'] := TRegistryIniFile(ExtObject).ReadString(Info['Section'], Info['Ident'], Info['Default']);
end;

procedure Tdws2RegIniLib.WriteStringEval;
begin
  TRegistryIniFile(ExtObject).WriteString(Info['Section'], Info['Ident'], Info['Value']);
end;

procedure Tdws2RegIniLib.EraseSectionEval;
begin
  TRegistryIniFile(ExtObject).EraseSection(Info['Section']);
end;

procedure Tdws2RegIniLib.DeleteKeyEval;
begin
  TRegistryIniFile(ExtObject).DeleteKey(Info['Section'], Info['Ident']);
end;

procedure Tdws2RegIniLib.UpdateFileEval;
begin
  TRegistryIniFile(ExtObject).UpdateFile;
end;

procedure Tdws2RegIniLib.SectionExistsEval;
begin
  Info['Result'] := TRegistryIniFile(ExtObject).SectionExists(Info['Section']);
end;

procedure Tdws2RegIniLib.ReadIntegerEval;
begin
  Info['Result'] := TRegistryIniFile(ExtObject).ReadInteger(Info['Section'], Info['Ident'], Info['Default']);
end;

procedure Tdws2RegIniLib.WriteIntegerEval;
begin
  TRegistryIniFile(ExtObject).WriteInteger(Info['Section'], Info['Ident'], Info['Value']);
end;

procedure Tdws2RegIniLib.ReadBoolEval;
begin
  Info['Result'] := TRegistryIniFile(ExtObject).ReadBool(Info['Section'], Info['Ident'], Info['Default']);
end;

procedure Tdws2RegIniLib.WriteBoolEval;
begin
  TRegistryIniFile(ExtObject).WriteBool(Info['Section'], Info['Ident'], Info['Value']);
end;

procedure Tdws2RegIniLib.ReadDateEval;
begin
  Info['Result'] := TRegistryIniFile(ExtObject).ReadDate(Info['Section'], Info['Ident'], Info['Default']);
end;

procedure Tdws2RegIniLib.WriteDateEval;
begin
  TRegistryIniFile(ExtObject).WriteDate(Info['Section'], Info['Ident'], Info['Value']);
end;

procedure Tdws2RegIniLib.ReadTimeEval;
begin
  Info['Result'] := TRegistryIniFile(ExtObject).ReadTime(Info['Section'], Info['Ident'], Info['Default']);
end;

procedure Tdws2RegIniLib.WriteTimeEval;
begin
  TRegistryIniFile(ExtObject).WriteTime(Info['Section'], Info['Ident'], Info['Value']);
end;

procedure Tdws2RegIniLib.ReadDateTimeEval;
begin
  Info['Result'] := TRegistryIniFile(ExtObject).ReadDateTime(Info['Section'], Info['Ident'], Info['Default']);
end;

procedure Tdws2RegIniLib.WriteDateTimeEval;
begin
  TRegistryIniFile(ExtObject).WriteDateTime(Info['Section'], Info['Ident'], Info['Value']);
end;

procedure Tdws2RegIniLib.ReadFloatEval;
begin
  Info['Result'] := TRegistryIniFile(ExtObject).ReadFloat(Info['Section'], Info['Ident'], Info['Default']);
end;

procedure Tdws2RegIniLib.WriteFloatEval;
begin
  TRegistryIniFile(ExtObject).WriteFloat(Info['Section'], Info['Ident'], Info['Value']);
end;

procedure Tdws2RegIniLib.ValueExistsEval;
begin
  Info['Result'] := TRegistryIniFile(ExtObject).ValueExists(Info['Section'], Info['Ident']);
end;

procedure Tdws2RegIniLib.ReadSectionEval;
begin
  TRegistryIniFile(ExtObject).ReadSection(Info['Section'],
    TStringList(IScriptObj(IUnknown(Info['Strings'])).ExternalObject));
end;

procedure Tdws2RegIniLib.ReadSectionsEval;
begin
  TRegistryIniFile(ExtObject).ReadSections(
    TStringList(IScriptObj(IUnknown(Info['Strings'])).ExternalObject));
end;

procedure Tdws2RegIniLib.ReadSectionValuesEval;
begin
  TRegistryIniFile(ExtObject).ReadSectionValues(Info['Section'],
    TStringList(IScriptObj(IUnknown(Info['Strings'])).ExternalObject));
end;

procedure Tdws2RegIniLib.DestructEval;
begin
  ExtObject.Free;
end;

end.

⌨️ 快捷键说明

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