How to read binary field

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Posts: 10
Joined: Mon 26 Jun 2006 19:23

How to read binary field

Post by Zoran565 » Sat 01 Jul 2006 18:11

In a table I have binary field in length of 16.

How do I get value of that field into MyArray: array[0..15] of byte;

I've tried "MSQuery1.FieldByName('...').GetData(@MyArray)", it transfers correct value into MyArray but after the end of procedure I get "Access Violation --- read of address 0x0010..."

What am I doing wrong?

I understand I can get this field AsString and then convert it to byte array, but I would like to avoid unnecessary processing.


Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Mon 03 Jul 2006 09:22

Value of VARBINARY field contains its length + data. So you have to allocate buffer with size = field size + 2 bytes;
In your case MyArray must be declared as array[0..17] of byte.
To get the data you can use the following construction: MSQuery1.FieldByName('...').GetData(@MyArray[0])

Post Reply