Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using ReadBinaryData with TMemoryStream

210 views
Skip to first unread message

Travis Martin

unread,
Sep 30, 1999, 3:00:00 AM9/30/99
to
I'm trying to read binary data from the registry into a TMemoryStream.
I am getting an access violation after reading from the
registry and setting the TMemoryStream.position to 0. I am assuming
that the read from the registry is failing but I'm not getting
any error message at that step. Thanks for any advice or suggestions.

Thanks
Travis Martin

var StringData : TStringStream;
BinaryData : TMemoryStream;
counter : integer;
Key : TKey64;
Deskey : string;
AFCUReg : TRegistry;
EncryptedProgname : shortString;
FirstPrivs,LastPrivs,TempStr: shortString;
begin

StringData := TStringStream.Create('');
BinaryData := TMemoryStream.Create;
BinaryData.SetSize(256);
BinaryData.Position := 0;

AFCUReg := TRegistry.Create;
AFCUReg.RootKey := HKEY_LOCAL_MACHINE;

EncryptedProgname := 'Casetrac1';

AFCUReg.OpenKey('\SOFTWARE\AFCU\CSAIR\OBJECT MODULES',TRUE);
AFCUReg.ReadBinaryData(EncryptedProgname,BinaryData,256);

BinaryData.Position := 0; //This line causes an access
violation.
StringData.Position := 0;


Frederick C. Wilt

unread,
Sep 30, 1999, 3:00:00 AM9/30/99
to

Travis Martin <tma...@americafirst.com> wrote in message
news:37F386A4...@americafirst.com...

> AFCUReg.ReadBinaryData(EncryptedProgname,BinaryData,256);

BinaryData is the reference to the memory stream object itself not the data
stored in the stream. You might try BinaryData.Memory. I didn't have time so
I haven't a clue. But check the on-line help for TMemoryStream.

Regards, Frederick C. Wilt


Peter Below (TeamB)

unread,
Sep 30, 1999, 3:00:00 AM9/30/99
to
In article <37F386A4...@americafirst.com>, Travis Martin wrote:
> AFCUReg.ReadBinaryData(EncryptedProgname,BinaryData,256);
>

Why do you think that this has any chance of working? You are passing
an object instance where the function requires a memory buffer. Change
the code to

AFCUReg.ReadBinaryData(EncryptedProgname,BinaryData.Memory^ ,256);

The syntax may look a bit weird but it is required since the Buffer
parameter for ReadBinaryData is an untyped Var parameter. This is also
the reason why the compiler happily accepted your code, an untyped Var
parameter will eat anything <g>.

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!


0 new messages