Solved

Registry - Binary Data (part 2)

Posted on 2004-10-14
7
625 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 22

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 500 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 115
Delphi...Split view - idea? 1 90
Drag & Drop... Data from one grid to another 2 42
Delphi Seattle StructureView color 1 15
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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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…

820 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