Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   How to write in registry hex key? (https://www.delphipraxis.net/57348-how-write-registry-hex-key.html)

alpha1 19. Nov 2005 17:28


How to write in registry hex key?
 
How can i write in registry hex key, like this: "Port"=hex:55,13,00,00 ? :wall:
Thanks!

Matze 19. Nov 2005 17:33

Re: How to write in registry hex key?
 
Hello, welcome in the forum!

Maybe this post will solve your problem: http://www.delphipraxis.net/internal...=285482#285482

alpha1 19. Nov 2005 20:26

Re: How to write in registry hex key?
 
I have already seen this post, but there is error in therein source: [Error] Project1.dpr(40): Constant object cannot be passed as var parameter.
How could I correct this error? :roll:

faux 19. Nov 2005 20:29

Re: How to write in registry hex key?
 
You have to initialize the reg-variable. Post your source-code here, so it's easier to help you. ;)

alpha1 19. Nov 2005 20:40

Re: How to write in registry hex key?
 
Delphi-Quellcode:
program Test;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Registry,
  Windows;

var
  Reg : TRegistry;
  buf: array[0..3] of byte;

begin
  buf[0] := $01;
  buf[1] := $00;
  buf[2] := $00;
  buf[3] := $00;

  Reg:=TRegistry.Create;
  Reg.RootKey:=HKEY_LOCAL_MACHINE;
  Reg.OpenKey('SYSTEM', False);
  Reg.CreateKey('Parameters');
  Reg.OpenKey('Parameters', False);
  Reg.WriteBinaryData('Test', @buf, 4);
  Reg.CloseKey;
  Reg.Free;
end.
Here is an error: [Error] Project1.dpr(25): Constant object cannot be passed as var parameter

marabu 19. Nov 2005 20:53

Re: How to write in registry hex key?
 
Hi alpha1,

you might want to try:

Delphi-Quellcode:
Reg.WriteBinaryData('Test', buf[0], Length(buf));
marabu

malo 19. Nov 2005 20:58

Re: How to write in registry hex key?
 
btw, that code is better:

Delphi-Quellcode:
program Test;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Registry,
  Windows;

var
  Reg : TRegistry;
  buf: array[0..3] of byte;

begin
  buf[0] := $01;
  buf[1] := $00;
  buf[2] := $00;
  buf[3] := $00;

  try // try-finally needed. If there is an exception anywhere, the object maybe does not free.
    Reg:=TRegistry.Create;
    Reg.RootKey:=HKEY_LOCAL_MACHINE;
    Reg.OpenKey('SYSTEM', False);
    Reg.CreateKey('Parameters');
    Reg.OpenKey('Parameters', False);
    Reg.WriteBinaryData('Test', buf, 4); // hier was the error. You don't need to put a pointer here
    Reg.CloseKey;
  finally // now free the object
    Reg.Free;
  end;
end.

alpha1 19. Nov 2005 21:12

Re: How to write in registry hex key?
 
Thanks!!!!!!! :thumb:


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:34 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz