Windows Registry

WINDOWS only

WriteRegistryString(REG_KEY_PATH, 'LastPreset', selectedPreset.asString);
Trace('Preset', ReadRegistryString(REG_KEY_PATH, 'LastPreset'));
Procedure Description
procedure WriteRegistryInteger(AKey, AName: string; AValue: integer); Write an integer value to the Windows registry under the specified key and name
procedure WriteRegistryString(AKey, AName: string; AValue: string); Write a string value to the Windows registry under the specified key and name
function ReadRegistryInteger(AKey, AName: string): integer; Read an integer value from the Windows registry for the specified key and name
function ReadRegistryString(AKey, AName: string): string; Read a string value from the Windows registry for the specified key and name
////////////////////////////////////////////////////////////////////////////////
// Registry Access Demo - demonstrates writing and reading string/integer pairs
// from the Windows registry. The example targets HKCU to keep the footprint safe.
////////////////////////////////////////////////////////////////////////////////

const REG_KEY_PATH = 'HKEY_CURRENT_USER\Software\UsineDemo\RegistryAccessDemo';
const REG_NAME_TEXT = 'LastUserNote';
const REG_NAME_INT  = 'LastUserNumber';

var
  WriteBtn    : TParameter;
  ReadBtn     : TParameter;
  TextInput   : TParameter;
  NumberInput : TParameter;
  TextOutput  : TParameter;
  NumberOutput: TParameter;
  InfoText    : TParameter;

procedure WriteToRegistry;
var
  intValue: integer;
begin
  intValue := Round(NumberInput.asFloat);
  WriteRegistryString(REG_KEY_PATH, REG_NAME_TEXT, TextInput.asString);
  WriteRegistryInteger(REG_KEY_PATH, REG_NAME_INT, intValue);
  InfoText.asString('Values written to ' + REG_KEY_PATH + '.');
end;

procedure ReadFromRegistry;
var
  storedText: string;
  storedInt : integer;
begin
  storedText := ReadRegistryString(REG_KEY_PATH, REG_NAME_TEXT);
  storedInt  := ReadRegistryInteger(REG_KEY_PATH, REG_NAME_INT);

  TextOutput.asString(storedText);
  NumberOutput.asFloat(storedInt);
  InfoText.asString('Values fetched from ' + REG_KEY_PATH + '.');
end;

procedure Init;
begin
  ModuleColor($FF1565C0);

  WriteBtn     := CreateParam('write registry', ptButton,    pioInput);
  ReadBtn      := CreateParam('read registry',  ptButton,    pioInput);
  TextInput    := CreateParam('text in',        ptTextField, pioInput);
  NumberInput  := CreateParam('number in',      ptDataFader, pioInput);
  TextOutput   := CreateParam('text out',       ptTextField, pioOutput);
  NumberOutput := CreateParam('number out',     ptDataField, pioOutput);
  InfoText     := CreateParam('info',           ptTextField, pioOutput);

  NumberInput.Min(0);
  NumberInput.Max(9999);
  NumberInput.AsFloat(42);

  NumberOutput.Min(0);
  NumberOutput.Max(9999);

  InfoText.asString('Press "write registry" to store the values under HKCU.');
end;

procedure Callback(N: integer);
begin
  if N = WriteBtn then
    WriteToRegistry;

  if N = ReadBtn then
    ReadFromRegistry;
end;

more about scripts

version 7.0.250121

Edit All Pages