Exported from Bugzilla, issue 3848.
--- Comment added on 9/16/2002 2:14:27 PM ---
Customer Requested:
-------------------->8 cut here 8<--------------------
Subject: TStBits to Byte conversion
Date: Tue, 23 Jul 2002 12:25:41 -0500
From: "Oliver Bailey" <oliver@time-lines.com>
Organization: Timelines Industries inc
Newsgroups: turbopower.public.support.systools
Hi,
We are using BinaryLS to read a four byte word. we then use TStBits to
change some bit settings. We are trying to read 8 TStBits as a byte to do a
simple byte wide compare. Nothing we have used works. Is there a simple
example somewhere that shows how this can be done.We've used about every
type of pointer and conversion possible on the starting element
TSTBit[element] and the TStBits.Items[element] with no success.
-------------------->8 cut here 8<--------------------
reply:
-------------------->8 cut here 8<--------------------
That last approach will not work, TBitSet.Items is not a true array.
While the desire to do what you describe seems fairly obvious, the
TStBits class doesn't actually account for it directly.
Using the class as-is the only option would be to read the bits
individually and re-construct the bit pattern in a new variable,
something like:
var
Value : Integer;
i : Integer;
begin
Value := 0;
for i := 31 downto 0 do begin
if Bits.Items[i] then
Value := Value or 1;
if i > 0 then
Value := Value shl 1;
end;
...
An alternative is to access the data pointer by opening TStBits'
protected section (using a protected section "cracker class"), this lets
you access the bit data directly:
type
TStBits = class(StBits.TStBits); // cracker class
...
var
Value : Integer;
begin
Move(Bits.btBits^, Value, 4);
I'll also take your question as a suggestion to add a facility to read
and write bit data from from and to other variables, and add that to the
wishlist.
-------------------->8 cut here 8<--------------------