Page 1 of 1

How to read binary field

Posted: Sat 01 Jul 2006 18:11
by Zoran565
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.

Thanks.

Posted: Mon 03 Jul 2006 09:22
by Jackson
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])