Re: bitwise operation doesn't work, what am I doing wrong?
- From: MikyMike <abcdef70@xxxxxxxxxxx>
- Date: Wed, 27 Dec 2006 22:11:28 -0500
Hi, sorry, I agree that the first line was supposed to be:
Alignment := DT_LEFT or DT_VCENTER;
I think I understand, but still not sure. Maybe what I want to do is
not a bitwise operation....
What I'm trying to do is know if Alignment containt DT_LEFT.
DT_LEFT and DT_VCENTER are some of the flags used with the function
named DrawText() in Windows unit. The function is:
function DrawText(hDC: HDC; lpString: PChar; nCount: Integer;
var lpRect: TRect; Alignment: UINT): Integer;
where Alignment can be one or many flags, like:
Alignment := DT_BOTTOM or DT_LEFT
Alignment := DT_BOTTOM or DT_LEFT or DT_CALCRECT or DT_SINGLELINE;
If I set many flags in Alignment, how I can check if DT_LEFT as been
set in Alignment or not? I tought I could use:
If (Alignment And DT_LEFT) <> 0 Then...
Do you have any suggestion?
On Wed, 27 Dec 2006 20:49:01 -0500, Jamie
<jamie_ka1lpa_not_valid_after_ka1lpa_@xxxxxxxxxxx> wrote:
MikyMike wrote:
assuming Both constants are not the same.
Hi, I try to do a bitwise operation to see if Alignment containt
DT_LEFT, but it always return false. Anyone have an idea why this
doesn't work?
procedure TForm1.Button1Click(Sender: TObject);
Var Alignment : Cardinal;
begin
Alignment := DT_LEFT and DT_VCENTER;
If (Alignment And DT_LEFT) <> 0 Then Caption := 'yes' else Caption
:= 'no';
end;
the Results will always be false.
i think what you're trying to do is set both flags.
try this.
Alignment := DT_LEFT Or DT_VCENTER.
with the "OR" you're setting the results to true if either
the Alignment current value has the bit set or the DT_VCENTER is set.
where is.
Alignment := DT_LEFT, then Alignment := Alignment or DT_VCENTER.
using the AND operator.
Both values in the same Bit location must be set before the results
is also set.
Basically, it means this.
One and the other Must match before the Results also matches.
seeing that DT_LEFT , DT_VCENTER most likely do not match, neither
one of them will be in the results. Or, if they have some bits in there
values that just happen to have the same values, only those bits will be
the results, how ever, the value most likely won't match either one.
for example
Value1 = $0F;
Value2 = $F0;
Results := Value1 and Value2; will = 0. because both values have bits
turn on that do not match each other.
here is another scenario.
Value1 = $1F;
Value2 = $F0;
Results := Value1 and Value2; will = $10; etc..
The AND operator is not an operation like A+B where is, the +
would be the "AND"
it simple means for example, IF Bit1 of Value 1 is on and Bit 1
of Value 2 is on, then the results at that bit location would also be
on. All bits are evaluated this way.
with OR,
If Bit 1 in value 1 is on or, Bit 1 in value 2 is on, the results is,
bit 1 is on.
hope that helped.
.
- References:
- bitwise operation doesn't work, what am I doing wrong?
- From: MikyMike
- Re: bitwise operation doesn't work, what am I doing wrong?
- From: Jamie
- bitwise operation doesn't work, what am I doing wrong?
- Prev by Date: Re: bitwise operation doesn't work, what am I doing wrong?
- Next by Date: Re: bitwise operation doesn't work, what am I doing wrong?
- Previous by thread: Re: bitwise operation doesn't work, what am I doing wrong?
- Next by thread: Re: bitwise operation doesn't work, what am I doing wrong?
- Index(es):