BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-26-2010, 06:26 PM   #1 (permalink)
New Member
 
Join Date: Apr 2010
Model: 9550
PIN: N/A
Carrier: Movistar
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Syntax question and weird result field.getStyle()

Please Login to Remove!

Im kind of new to BlackBerry and Java programming. I'm an experienced AS3
developer and use the Eclipse IDE. I'm reading a beginners book for developing
on BlackBerry devices. Now I have two questions for things that are not clear for me. Both questions are I think related to each other.

1. I have the following code, but I dont understand the syntax of it:
if((field.getStyle() & Field.FIELD_RIGHT) == Field.Field_RIGHT) {

I know it compairs these two variables but the first part I dont get. I set the
style of the field and then you have to do first something with with the static Field.FIELD_RIGHT before you can test if it is equal?

2. I tried to understand the above code with making to test long variables and do something with another Field style. But when I checked with the debugger which values were set inside test1 and test2 they were both the
same? Is this right or is it that I dont understand the syntax yet of this code line? Or is this a bug in the JDE 5?
long test1 = (field.getStyle() & Field.FIELD_RIGHT);
long test2 = (field.getStyle() & Field.FIELD_HCENTER);

I hope somebody can help me with this I hope its not a tooo NOOB question
:-D
Offline  
Old 04-27-2010, 02:06 PM   #2 (permalink)
New Member
 
Join Date: Apr 2010
Model: 9550
PIN: N/A
Carrier: Movistar
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Solution

Okay, I have found the solution by using a some googling. I will try now to explain the solution, so maybe this can be useful to some other people that have the same question. What the .. is going on here???

First of all I found what is happening in the line:
(field.getStyle() & Field.FIELD_RIGHT)

The following takes place on binary level:
10100000000000100000001000000000000000000000000000 000000
00000000000000000000001000000000000000000000000000 000000 AND
----------------------------------------------------------------
00000000000000000000001000000000000000000000000000 000000

So let me try to explain it simple the following value in field.getStyle() are all the flags that define the styles of this field. So if you try to watch the value with the debugger you get an decimal result, but actually you need to look a little bit deeper into the binary code of this value. In order to filter out the right style flag to compare it with the same style flag you do the AND binary operand. This operand will return only the flags that are set on both binary values.

field.getStyle() = 10100000000000100000001000000000000000000000000000 000000
Field.FIELD_RIGHT = 00000000000000000000001000000000000000000000000000 000000 AND
will result into:
----------------------------------------------------------------
00000000000000000000001000000000000000000000000000 000000

So if you have the following line (field.getStyle() & Field.FIELD_LEFT)

field.getStyle() = 10100000000000100000001000000000000000000000000000 000000
Field.FIELD_LEFT = 00000000000000000000000100000000000000000000000000 000000 AND
will result into:
----------------------------------------------------------------
00000000000000000000000000000000000000000000000000 000000

So this works pretty well. But I found a little problem or error to watch out for when you want to use the style flag Field.FIELD_HCENTER this one has the flags for Field.FIELD_RIGHT and Field.FIELD_LEFT set so in both equations above it will return into "true" (false positive). So if you want to check for these three style options. You have to check first for Field.FIELD_RIGHT and for Field.FIELD_LEFT and then as last for Field.FIELD_HCENTER so it wont act as one of the others but as a Horizontal Center. If you do opposite so you check for Field.FIELD_HCENTER and then for Field.FIELD_RIGHT you will overwrite everything you have done inside the Field.FIELD_HCENTER.

I hope this is clear now for everybody with the same question. If not let me know and I will try to explain different. If I said something wrong please correct me :-D
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.