Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Reading Binary Data with TRegistry

Posted on 2003-12-05
1
541 Views
Last Modified: 2010-04-05
I am currently writing an application where I need to be able to read various registry enteries without knowing their types beforehand. All the information read from the registry will be converted to a string. I have written a small bit of code that pretty much handles this, but I am having a problem with binary data. My code is as follows:

        MyReg.OpenKey(RegKey, False);
        RegType := MyReg.GetDataType(RegValue);
        if (RegType = rdString) or (RegType = rdExpandString) then sData := MyReg.ReadString(sValue);
        if RegType = rdInteger then sData := IntToStr(MyReg.ReadInteger(sValue));
        if RegType = rdBinary then
        begin
            lBinaryDataSize := MyReg.GetDataSize(sValue);
            SetLength(Buffer, lBinaryDataSize);

            MyReg.ReadBinaryData(RegValue, Buffer, SizeOf(Buffer));
       end;

"RegKey", "RegValue" are both strings whose values are predetermined earlier in the code. "Buffer" is an array of byte, which as you can see, is resized based on the size of the binary data.

The error I am recieving is when I actually come across some binary data in the registry. Despite the fact that the key type is rdBinary, I get a message that says "Invalid Data Type For 'CustomColors'" (which is the particular key I am trying to read). Any idea of what I may be doing wrong?
0
Comment
Question by:Thora_Fan
1 Comment
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 125 total points
ID: 9881015
     
MyReg.OpenKey(RegKey, False);
        RegType := MyReg.GetDataType(RegValue);
        if (RegType = rdString) or (RegType = rdExpandString) then sData := MyReg.ReadString(sValue);
        if RegType = rdInteger then sData := IntToStr(MyReg.ReadInteger(sValue));
        if RegType = rdBinary then
        begin
            lBinaryDataSize := MyReg.GetDataSize(sValue);
            SetLength(Buffer, lBinaryDataSize);
            If lBinaryDataSize > 0 then
               MyReg.ReadBinaryData(RegValue, Buffer[0], lBinaryDataSize);
       end;

F68 ;-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question