Board index » delphi » Converting Bin Value To String

Converting Bin Value To String

Hi!
I want to convert a binary value from a registry key to a string value to
use in my application. Does anybody knows how to do this?
Thanks,
Ulrich
 

Re:Converting Bin Value To String


"Ulrich Berlinghof" <u.berling...@dralion.de> skrev i melding
news:9bjqpj$356$1@news1.wdf.sap-ag.de...

Quote
> Hi!
> I want to convert a binary value from a registry key to a string value to
> use in my application. Does anybody knows how to do this?
> Thanks,
> Ulrich

You want to convert them to Characters ?

  $414243 => "ABC"

...or

  $414243 => "$414243"

???

--
Bjoerge Saether
Consultant / Developer
http://www.itte.no
Asker, Norway
bjorgeremovet...@itte.no (remove the obvious)

Re:Converting Bin Value To String


Hi!
Thanks for your answer. Yes I want characters..

Ulrich

Quote
"Bj?rge S?ther" <REMOVE_bsaether@THIS_online.no> wrote in message

news:JpgD6.10465$NR.819353@news3.oke.nextra.no...
Quote
> "Ulrich Berlinghof" <u.berling...@dralion.de> skrev i melding
> news:9bjqpj$356$1@news1.wdf.sap-ag.de...
> > Hi!
> > I want to convert a binary value from a registry key to a string value
to
> > use in my application. Does anybody knows how to do this?
> > Thanks,
> > Ulrich

> You want to convert them to Characters ?

>   $414243 => "ABC"

> ...or

>   $414243 => "$414243"

> ???

> --
> Bjoerge Saether
> Consultant / Developer
> http://www.itte.no
> Asker, Norway
> bjorgeremovet...@itte.no (remove the obvious)

Re:Converting Bin Value To String


Example:

uses
  Registry;

function GetBinaryValue(const Root: HKEY; const Key, Name: String): String;
var
  R: TRegistry;
begin
  R := TRegistry.Create;
  try
    R.RootKey := Root;
    if R.OpenKey(Key, False) then
    begin
      SetLength(Result, R.GetDataSize(Name));
      R.ReadBinaryData(Name, Result[1], Length(Result));
    end;
  finally
    R.Free;
  end;
end;

"Ulrich Berlinghof" <u.berling...@dralion.de> schreef in bericht
news:9bjqpj$356$1@news1.wdf.sap-ag.de...

Quote
> Hi!
> I want to convert a binary value from a registry key to a string value to
> use in my application. Does anybody knows how to do this?
> Thanks,
> Ulrich

Re:Converting Bin Value To String


Thanks,
I tried this but the result is not usable for me. Meanwhile I tried this:

...
const
  Key  : String = '\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Management\ARPCache\Delphi5';
  Val  : String = 'SlowInfoCache';
 var
  Data : Array of Byte;
  S    : String;
  sz   : Word;
  I    : Word;
  R    : TRegistry;
 begin
  R := TRegistry.Create;
  with R do
   begin
     RootKey := HKEY_LOCAL_MACHINE;
     OpenKey(Key, False);
    if GetDataType(Val) = rdBinary
     then
      begin
       sz := GetDataSize(Val);
       if sz > 0 then
        begin
         SetLength(Data, sz);
         ReadBinaryData(Val, Data[0], sz);
         S := Val + ' = ';
         for I := 0 to sz - 1 do
          begin
           S := S + Format('%2x',[Data[I]]);
          end;
......
This is the result I got:
8 2 0 0 1 0 0 0 080E8 9 0 0 0 0D09B1539 7C7C0 1 9 0 0 043 03A 05C 050 072
06F 067 072 061 06D 020 046 069 06C 065 073 05C 042 06F 072 06C 061 06E 064
05C 044 065 06C 070 068 069 035 05C 048 065 06C 070 05C 054 06F 06F 06C 073
05C 068 063 077 02E 065 078 065 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

So how can I get a readable string out of this data?

Thanks,
Ulrich

Quote
"M.H. Avegaart" <avegaartNOS...@mccomm.nl> wrote in message

news:9bm5n2$req$1@porthos.nl.uu.net...
Quote
> Example:

> uses
>   Registry;

> function GetBinaryValue(const Root: HKEY; const Key, Name: String):
String;
> var
>   R: TRegistry;
> begin
>   R := TRegistry.Create;
>   try
>     R.RootKey := Root;
>     if R.OpenKey(Key, False) then
>     begin
>       SetLength(Result, R.GetDataSize(Name));
>       R.ReadBinaryData(Name, Result[1], Length(Result));
>     end;
>   finally
>     R.Free;
>   end;
> end;

> "Ulrich Berlinghof" <u.berling...@dralion.de> schreef in bericht
> news:9bjqpj$356$1@news1.wdf.sap-ag.de...
> > Hi!
> > I want to convert a binary value from a registry key to a string value
to
> > use in my application. Does anybody knows how to do this?
> > Thanks,
> > Ulrich

Re:Converting Bin Value To String


You'll have to replace all non-ASCII characters with a dummy character
(e.g. -).

function GetBinaryValue(const Root: HKEY; const Key, Name: String): String;
var
  R: TRegistry;
  i: Integer;
begin
  R := TRegistry.Create;
  try
    R.RootKey := Root;
    if R.OpenKey(Key, False) then
    begin
      SetLength(Result, R.GetDataSize(Name));
      R.ReadBinaryData(Name, Result[1], Length(Result));
      for i := 1 to Length(Result) do
        if (Result[i] < #32) or (Result[i] > #126) then
          Result[i] := '-';
    end;
  finally
    R.Free;
  end;
end;

"Ulrich Berlinghof" <u.berling...@dralion.de> schreef in bericht
news:9bmden$ji6$1@news1.wdf.sap-ag.de...

Quote
> Thanks,
> I tried this but the result is not usable for me. Meanwhile I tried this:

> ...
> const
>   Key  : String = '\SOFTWARE\Microsoft\Windows\CurrentVersion\App
> Management\ARPCache\Delphi5';
>   Val  : String = 'SlowInfoCache';
>  var
>   Data : Array of Byte;
>   S    : String;
>   sz   : Word;
>   I    : Word;
>   R    : TRegistry;
>  begin
>   R := TRegistry.Create;
>   with R do
>    begin
>      RootKey := HKEY_LOCAL_MACHINE;
>      OpenKey(Key, False);
>     if GetDataType(Val) = rdBinary
>      then
>       begin
>        sz := GetDataSize(Val);
>        if sz > 0 then
>         begin
>          SetLength(Data, sz);
>          ReadBinaryData(Val, Data[0], sz);
>          S := Val + ' = ';
>          for I := 0 to sz - 1 do
>           begin
>            S := S + Format('%2x',[Data[I]]);
>           end;
> ......
> This is the result I got:
> 8 2 0 0 1 0 0 0 080E8 9 0 0 0 0D09B1539 7C7C0 1 9 0 0 043 03A 05C 050 072
> 06F 067 072 061 06D 020 046 069 06C 065 073 05C 042 06F 072 06C 061 06E
064
> 05C 044 065 06C 070 068 069 035 05C 048 065 06C 070 05C 054 06F 06F 06C
073
> 05C 068 063 077 02E 065 078 065 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

> So how can I get a readable string out of this data?

> Thanks,
> Ulrich

> "M.H. Avegaart" <avegaartNOS...@mccomm.nl> wrote in message
> news:9bm5n2$req$1@porthos.nl.uu.net...
> > Example:

> > uses
> >   Registry;

> > function GetBinaryValue(const Root: HKEY; const Key, Name: String):
> String;
> > var
> >   R: TRegistry;
> > begin
> >   R := TRegistry.Create;
> >   try
> >     R.RootKey := Root;
> >     if R.OpenKey(Key, False) then
> >     begin
> >       SetLength(Result, R.GetDataSize(Name));
> >       R.ReadBinaryData(Name, Result[1], Length(Result));
> >     end;
> >   finally
> >     R.Free;
> >   end;
> > end;

> > "Ulrich Berlinghof" <u.berling...@dralion.de> schreef in bericht
> > news:9bjqpj$356$1@news1.wdf.sap-ag.de...
> > > Hi!
> > > I want to convert a binary value from a registry key to a string value
> to
> > > use in my application. Does anybody knows how to do this?
> > > Thanks,
> > > Ulrich

Other Threads