Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 14 total
Thread How do you all access byte fields?
Thu, Aug 16 2012 8:13 PMPermanent Link

Dominique Willems

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

I have tried to use AsString, but it returns empty. AsInteger, the
obvious choice, gives me "cannot access field as type integer."

I'm sure there is a really really simple solution, so I'm looking
forward to the answer. Cheers!
Sun, Aug 19 2012 1:07 AMPermanent Link

Barry

Dominique,
  How did you put the data into the byte fields?

Barry
Sun, Aug 19 2012 10:30 AMPermanent Link

Malcolm Taylor

Dominique Willems wrote:

> A truly humongously stupid question, I am sure, but I am curious as to
> how you access your one-byte fields?
>
> I have tried to use AsString, but it returns empty. AsInteger, the
> obvious choice, gives me "cannot access field as type integer."
>
> I'm sure there is a really really simple solution, so I'm looking
> forward to the answer. Cheers!

Hmm, I don't have such types but have you tried .AsBytes ?
Sun, Aug 19 2012 11:16 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Dominique


What datatype are you using to create the column in the table? One problem will probably be that some types either don't match well to their potential Delphi equivalent of just don't match.

I just created a 1 Byte column - what you have to do is

procedure TForm1.Button1Click(Sender: TObject);
var
xx:string;
yy:integer;
begin
xx:=test.fieldbyname('_bytes').asstring;
yy:=ord(xx[1]);
showmessage(inttostr(yy));
end;


In my case I'd shoved 05 into it in EDBManager

Roy Lambert
Mon, Aug 20 2012 7:49 AMPermanent Link

Dominique Willems

Barry wrote:
> Dominique,
>    How did you put the data into the byte fields?

..AsString.

And to read it:
Ord(tbTestByte.AsString[1])

but it was returning empty strings. So I gave up and am now just using
SmallInt fields. Bit of a waste, but more elegant. If only a byte field
were accessible through AsInteger.
Mon, Aug 20 2012 7:49 AMPermanent Link

Dominique Willems

Malcolm wrote:
> Hmm, I don't have such types but have you tried .AsBytes ?

I have. Unsuccessfully.
Mon, Aug 20 2012 7:50 AMPermanent Link

Dominique Willems

Roy Lambert wrote:
> xx:=test.fieldbyname('_bytes').asstring;
> yy:=ord(xx[1]);

I got access violations because the string was empty, while the field
never was. Odd, but I eventually gave up and reverted to SmallInt
fields.
Mon, Aug 20 2012 8:26 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Dominique


Was it unicode or ansi? I tested using ansi cos that's what I use.

Roy Lambert [Team Elevate]
Mon, Aug 20 2012 8:58 AMPermanent Link

Dominique Willems

Roy Lambert wrote:
> Was it unicode or ansi? I tested using ansi cos that's what I use.

Unicode.
Mon, Aug 20 2012 10:16 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Dominique


<WARNING>

Everything that follows is a guess because I'm still running D2006.

</WARNING>

In that case you may be hitting the ansi/unicode problem. field.AsString will return a unicode string, Ord I assume has be altered to handle this but you're passing it a single byte and its throwing a wobbly.

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.

Roy Lambert [Team Elevate]
Page 1 of 2Next Page »
Jump to Page:  1 2
Image