Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reading Binary Data with TRegistry

Posted on 2003-12-05
1
Medium Priority
?
563 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
[X]
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
1 Comment
 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

722 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