Solved

Reading Binary Data with TRegistry

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

920 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

14 Experts available now in Live!

Get 1:1 Help Now