Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Registry - Binary Data (part 2)

Posted on 2004-10-14
7
Medium Priority
?
629 Views
Last Modified: 2012-05-05
Might seem like an odd thing to do but...

I have loaded an array of bytes with binary data from the registry (this works perfectly so far)

now what i want to do is move the contents of the array into a record.  I have used Copymemory and even Movememory but it doesn't work. I am using Delphi 4 Professional - if that helps.

example:

Type
      TCardValues = packed record
       Deck: integer;
       Name: string[200];
       Card: Integer;
       Pos  : Integer;
       Picked : Boolean;
end;

var

    Card : TCardValues;

{rest of program}


I use this procedure to load the information back from the registry

procedure Load;
var
Buffer: Array of bytes
begin
 
   {call routine to get binary data from registry - Buffer will then contain returned data}
   

I have tried:  movememory(@card, buf, length(buf));  and it seems to work but then the program displays a runtime error 216 on exit
If i use movememory(@card, buf, sizeof(buf)); the error stops but i don't get the entire information back into the card record
and movememory(@card, buf[1], sizeof(buf)); or movememory(@card, buf[1], length(buf));  does not even compile


end;

0
Comment
Question by:mi6agent
7 Comments
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 12307589
I assume that you're using RegReadBinary from the previous question to fill the buffer....

The RegReadBinary result is the size of the buffer so try using it directly....

Var BufSize:  cardinal;

BufSize := RegReadBinary(......

movememory(@card, buf, BufSize);
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12307622
Have you tried:

Move(Buf,Card,sizeof(Card));

0
 
LVL 7

Accepted Solution

by:
LRHGuy earned 2000 total points
ID: 12307683
After some testing, I discovered that either of these should work for you:

  move(buf[0],card,sizeof(card));
  movememory(@card,@buf[0],sizeof(card));

Referencing the first element of the array is the "trick".
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:mi6agent
ID: 12307924
>I assume that you're using RegReadBinary from the previous question to fill the buffer....

Yes, i am using that routine to grab the information.

Tried movememory(@card, buf, BufSize);  - still no luck


>Have you tried: Move(Buf,Card,sizeof(Card));

Yep, didn't work either

0
 

Author Comment

by:mi6agent
ID: 12308080
Thanks LRHGuy - i'll give them both a try out and get back to you asap
0
 
LVL 34

Expert Comment

by:Slick812
ID: 12311039
not sure about all of the code you use? But To me, it seems like you may be doing an extra Step that I would skip, , , It seems like you use some sort of "Buffer" as an array of Byte to get the reg data, and then you want to transfer this bufffer to a TCardValues . . .  I would just put the data into the TCardValues in the first Reg Read operation and then I would not need a buffer, maybe something like this -

var
    Card : TCardValues;

ReadRegBinary(aKey, regName, Card, SizeOf(Card)):


this is untested, from my head, but my suggestion is to skip the Buffer transfer. .
0
 

Author Comment

by:mi6agent
ID: 12317437
Thanks to everyone for suggestions.

LRHGuy - i tested out your code and got it to work with no problem.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

879 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