Recent

Author Topic: Developing for Android with Pascal and Eclipse  (Read 27072 times)

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Developing for Android with Pascal and Eclipse
« Reply #15 on: November 09, 2012, 11:09:56 pm »
But even if this day become, I have doubts about writting android apps in lazarus. I'm afraid that I get stuck in the middle of the project, because for example I will can not use some android api in pascal.

If you use the FPC JVM compiler, it includes access to the entire android.jar in the included androidr14 unit. The "14" means API level 14, which corresponds to everything through Android 4.0.2. (Don't confuse API level or Android version with the SDK version, which is currently at 20.)
Thanks.

-Phil

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Developing for Android with Pascal and Eclipse
« Reply #16 on: November 10, 2012, 05:02:33 am »
Quote
If you use the FPC JVM compiler, it includes access to the entire android.jar in the included androidr14 unit
Indeed, and they work as if you write the application in Java. Only that since FPC doesn't support Java style packages, the class names must be flattened and sometimes it can't be guessed easily.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Developing for Android with Pascal and Eclipse
« Reply #17 on: November 10, 2012, 03:49:35 pm »
Quote
If you use the FPC JVM compiler, it includes access to the entire android.jar in the included androidr14 unit
the class names must be flattened and sometimes it can't be guessed easily.

Not sure if I follow. The Pascal name can always be determined easily from the Java package and class names. See note 2 here:

http://web.fastermac.net/~MacPgmr/pba/PbaStatus.html#Tips

Thanks.

-Phil

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Developing for Android with Pascal and Eclipse
« Reply #18 on: November 10, 2012, 05:16:15 pm »
Quote
Not sure if I follow. The Pascal name can always be determined easily from the Java package and class names. See note 2 here:

http://web.fastermac.net/~MacPgmr/pba/PbaStatus.html#Tips
Yes, indeed that works somewhat. Seems like not many (or none) classes have the same name under package namespace with same first letters (.e.g.: java.lang.Integer vs java.lazy.Integer in which both will be abbreviated to JLInteger according to the convention).

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Developing for Android with Pascal and Eclipse
« Reply #19 on: November 10, 2012, 05:47:08 pm »
Quote
Not sure if I follow. The Pascal name can always be determined easily from the Java package and class names. See note 2 here:

http://web.fastermac.net/~MacPgmr/pba/PbaStatus.html#Tips
Yes, indeed that works somewhat. Seems like not many (or none) classes have the same name under package namespace with same first letters (.e.g.: java.lang.Integer vs java.lazy.Integer in which both will be abbreviated to JLInteger according to the convention).

Right, if there is a naming conflict you would not be able to compile the Pascal interface unit. In that case, just change the name of one of the abbreviated class names. The only thing that matters is the package and Java class name in the declaration. For example:

Code: [Select]
ADSSQLiteDatabase = class external 'android.database.sqlite' name 'SQLiteDatabase' (ADSSQLiteClosable)

It doesn't matter what you use for the Pascal name as long as the package and Java class name are correct. In the case of the android.jar runtime, it appears as though there are no naming conflicts that need to be worked around manually (see http://wiki.freepascal.org/FPC_JVM/Building#Creating_the_Android_RTL_headers).

This is very much analogous to the way FPC's Objective Pascal dialect works. For example, if you want to call the setTitle:forState: method in the Objective-C UIButton class, here is how it would need to be declared in Pascal:

Code: [Select]
procedure setTitle_forState(title: NSString; state_: UIControlState); message 'setTitle:forState:';

The message specifies the actual Objective-C method name, meaning we can use whatever we want for the Pascal method name.

In both case, we're able to directly utilize the actual underlying classes (Java or Obj-C) in our Pascal code, with only minor compromises in syntax. This is really breakthrough technology and solves a lot of problems.

Thanks.

-Phil


Takeda

  • Full Member
  • ***
  • Posts: 157
Re: Developing for Android with Pascal and Eclipse
« Reply #21 on: November 11, 2012, 06:28:32 am »
The sound is good.. I love it...  ;)

Well, Phil I have a little question. Is possible for me, to adopt it on Windows 7?

Regards,
Takeda
Call me Takeda coz that's my true name.
Pascal coding using Lazarus => "Be native in any where.."

ƪ(˘⌣˘)┐ ƪ(˘⌣˘)ʃ ┌(˘⌣˘)ʃ

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Developing for Android with Pascal and Eclipse
« Reply #22 on: November 11, 2012, 04:19:33 pm »
Well, Phil I have a little question. Is possible for me, to adopt it on Windows 7?

Should be the same setup on Win7 as on Mac (or Linux). I only tested on Mac because that's what I use (and want to target iOS too).

Post here if you have problems (or success).

Thanks.

-Phil

stab

  • Full Member
  • ***
  • Posts: 234
Re: Developing for Android with Pascal and Eclipse
« Reply #23 on: November 12, 2012, 05:38:15 pm »
Hi Phil,

Tried to follow your instructions but got an error at
make FPCMAKE=$make_path CROSSOPT="-O2 -g" CPU_TARGET=jvm OS_TARGET=android INSTALL_PREFIX=$install_path all crossinstall
make: *** No rule to make `all'. Stop

Platform: Windows 7/64
FPC: 2.6.0

???

Regards
stab %)

Andru

  • Full Member
  • ***
  • Posts: 112
Re: Developing for Android with Pascal and Eclipse
« Reply #24 on: November 12, 2012, 06:17:42 pm »
stab
jvm available only in FPC 2.7.1

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Developing for Android with Pascal and Eclipse
« Reply #25 on: November 12, 2012, 07:11:22 pm »
Platform: Windows 7/64
FPC: 2.6.0

Are you compiling the checked-out SVN trunk source? You can't compile 2.6.0 source since it doesn't know anything about JVM.

Also make sure you're using the updated fpcmake compiled from trunk source.

Thanks.

-Phil

stab

  • Full Member
  • ***
  • Posts: 234
Re: Developing for Android with Pascal and Eclipse
« Reply #26 on: November 12, 2012, 07:49:08 pm »
Thanks for the info Phil and Andru

/stab ::)

Microges2000

  • New Member
  • *
  • Posts: 24
Re: Developing for Android with Pascal and Eclipse
« Reply #27 on: December 19, 2012, 10:35:35 am »
Good work.

I have slightly modified the parser because it was not compatible with the latest version of Eclipse (you can download the source here http://www.biotecnicainstruments.com/File/Temp/(Pascal%20builder).zip)

Now I have a little important question:

I have created a small application with one activity and a button called button1

Into the source i can modify the main form property, for example the text:

Code: [Select]
procedure MainActivity.onCreate(savedInstanceState: AOBundle);
begin
  inherited onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  SetTitle(R.Strings.my_new_title);
end;

and all is ok but how i can access to button1 property (for example text or OnClick event)? I tried various ways but nothing done!

Some idea?

 

TinyPortal © 2005-2018