Solved

Reading Binary Data with TRegistry

Posted on 2003-12-05
1
532 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now