BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 01-30-2008, 05:55 AM   #1 (permalink)
New Member
 
Join Date: Sep 2006
Model: 8800
Carrier: O2
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default ifdef in Blackberry JDE?

Please Login to Remove!

I'm building versions of an app for different OS versions, but would like to keep a single source. Does the Blackberry JDE support conditional defines? e.g.
//#ifdef OS4_2
or do I need to use a separate pre-processor like Ant?
Offline  
Old 01-30-2008, 07:28 AM   #2 (permalink)
New Member
 
Join Date: Jan 2008
Model: 8130
PIN: N/A
Carrier: Verizon
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wirelessly posted (BlackBerry8130/4.3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/105)

Quote:
Originally Posted by bwhelan
I'm building versions of an app for different OS versions, but would like to keep a single source. Does the Blackberry JDE support conditional defines? e.g.
//#ifdef OS4_2
or do I need to use a separate pre-processor like Ant?
The java compiler does not understand #define. You'll have to use a separate pre-processor.
Offline  
Old 01-30-2008, 10:10 AM   #3 (permalink)
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I use the pre-processor from Antenna, but only sparingly, and I don't use it for cross-platform compatibility. I've had too many experiences back in the day where every third line would be some device-specific work-around (which luckily isn't so much an issue in RIM).

Something I learned back in my server-side Spring days was to code to interfaces and then plug in the implementation. So you could have Interface IFoo which defines an API. Then, if you have common functionality put it into an Abstract base class. Then extend that abstract class for each of your OS-specific implementations. In your app, only refer to the interface, not to any of the implementations. Plug in the appropriate implementation in your ant script (or whatever you use). eg: "ant -Dos=421"
Offline  
Old 01-30-2008, 10:31 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2006
Location: Moscow
Model: 9000
OS: 4.6.0.304
Carrier: MTC
Posts: 72
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use j2mePolish (J2ME Polish)
Offline  
Old 02-01-2008, 01:55 AM   #5 (permalink)
Talking BlackBerry Encyclopedia
 
Skipper_Joe's Avatar
 
Join Date: Jan 2007
Location: Kharkov, Ukraine
Model: 8300
Carrier: N/A
Posts: 237
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

JDE itself doesn't support antenna preprocessor syntax, but you can do in next way:
Code:
//#ifdef OS4_2
    //# public static final boolean isOS42 = true;
//#else
   public static final boolean isOS42 = false;
//#endif
Notice that one of the source lines is commented with "//#" and is not parsed by IDE, so it doesn't show error here. But antenna knows such syntax and removes "//#" during preprocessor stage.

In general I agree with Richard - use interfaces and different implementations, where possible.
But sometimes it is not possible, so we need to do such tricks.
Offline  
Old 02-04-2008, 04:29 PM   #6 (permalink)
New Member
 
Join Date: Sep 2006
Model: 8800
Carrier: O2
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the advice!
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.