Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 14 of 14 total
Thread How do you all access byte fields?
Mon, Aug 20 2012 10:56 AMPermanent Link

Dominique Willems

Roy Lambert wrote:
> There may be a specific version for ansichar or you may have to
> explicity cast your data to ansichar to trigger overloading in the
> standard version.

In any case, it's big hoops to jump through to represent the most basic
of types. A little bit shaking head that in 2012 we don't have an
elegant way to store a byte in a database! (or at least store and
retrieve it elegantly)

Switched to SmallInt so that I don't have to do a "WTF!" when I look at
the code in a couple of months. Smile
Wed, Sep 5 2012 8:59 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Dom,

<< A truly humongously stupid question, I am sure, but I am curious as to
how you access your one-byte fields? >>

What version of Delphi are you using ?  There is less support for byte array
columns in older versions of Delphi, and more support now in XE and above.

In older versions like D7, you can use the following:

procedure TForm1.Button1Click(Sender: TObject);
var
  TempByte: Byte;
begin
  EDBTable1.FieldByName('ByteField').GetData(@TempByte,True);
  ShowMessage(Chr(TempByte));
end;

In newer versions, you can just use:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(Chr(EDBTable1.FieldByName('ByteField').AsBytes[0]));
end;

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Sep 5 2012 9:01 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Dom,

<< Switched to SmallInt so that I don't have to do a "WTF!" when I look at
the code in a couple of months. Smile>>

You're not really saving much space by going with a Byte or VarByte column
when you only want to store a single byte and manipulate it like an integer.
The Byte/VarByte column types are primarily *array of byte* column types and
are more geared toward storing binary structures, arrays, etc.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Sep 17 2012 5:54 AMPermanent Link

Dominique Willems

Tim Young [Elevate Software] wrote:
> You're not really saving much space by going with a Byte or VarByte
> column when you only want to store a single byte and manipulate it
> like an integer. The Byte/VarByte column types are primarily *array
> of byte* column types and are more geared toward storing binary
> structures, arrays, etc.

Okido, thanks for the info!
« Previous PagePage 2 of 2
Jump to Page:  1 2
Image