ppcjvm issues

classic Classic list List threaded Threaded
35 messages Options
12
Reply | Threaded
Open this post in threaded view
|

ppcjvm issues

Jon Foster
I've been working on building an app for Android using the FPC's JVM
target. I'm using fpc 3.0.0. I've run into a couple of things that I'm not
sure if they're bugs or I just don't know what I'm doing. I was using fpc
to avoid having to learn Java and have discovered that's not entirely
possible. :-/

The first issue I ran into is this:

procedure Cppp1Activity.onResume;
begin
     inherited onResume;
     with AAAlertDialog.InnerBuilder(self) do begin
         setTitle(R.strings.app_name);
     end;
end;

Cppp1Activity is a descendant of AAActivity. I'm overriding the onResume
method. The problem I ran into was with the AAAlertDialog.InnerBuilder
class. I can create an object of that class without incident. However if I
try to call any of the methods (tried several) I get a "Class Cast"
exception reported in the Android log and the app goes *poof*. I also tried
just chaining the call like
"AAAlertDialog.InnerBuilder(self).setTitle(R.strings.app_name);", and I
tried this in the "Activity.onCreate" method with the same result. And yes
"R.strings.app_name" points to an actual resource and I generated a
"resources.pas" with the "R" class fresh for this test.

The second issue I ran into:

function f(x, y: integer): float;
begin
     result:=float(dy)/float(dx)
end;

When attempting to compile this it tells me that "float" is undefined. I
think I'm missing something here. "float" is the native Java name for their
base floating point type and its a valid type for FPC. If I use "single"
instead it will compile. Seems odd.

THX - Jon

--
Sent from my Debian Linux workstation -- http://www.debian.org/intro/about

Jon Foster
JF Possibilities, Inc.
[hidden email]
541-410-2760
Making computers work for you!

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Tomas Hajny-2
On Sat, January 7, 2017 03:12, Jon Foster wrote:


Hello,

You didn't mention that you weren't subscribed to the list, but since this
seemed to be the case, I included your address in Cc:.


 .
 .

> The second issue I ran into:
>
> function f(x, y: integer): float;
> begin
>      result:=float(dy)/float(dx)
> end;
>
> When attempting to compile this it tells me that "float" is undefined. I
> think I'm missing something here. "float" is the native Java name for
> their
> base floating point type and its a valid type for FPC. If I use "single"
> instead it will compile. Seems odd.

I can't comment the first part, but where exactly is a type named "float"
defined in FPC (which unit)? E.g. single is defined in unit System and
thus available for all FPC programs automatically. If some unit defines
"float" (not sure about that, but it might be the case). I can see the
System unit for Java defining "jfloat" as an alias to single - maybe you
meant that one?

Hope this helps

Tomas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Bart-48
On 1/7/17, Tomas Hajny <[hidden email]> wrote:

> I can't comment the first part, but where exactly is a type named "float"
> defined in FPC (which unit)?

Float is defined in math unit.
It is an alias to float128, if that type exists, else extende, or else
to double, or else to single.

Bart
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Jon Foster
In reply to this post by Tomas Hajny-2
On 01/07/2017 03:06 AM, Tomas Hajny wrote:
> On Sat, January 7, 2017 03:12, Jon Foster wrote:
>
>
> Hello,
>
> You didn't mention that you weren't subscribed to the list, but since this
> seemed to be the case, I included your address in Cc:.
Thanks for this. I get a lot of mail from the FPC lists ... but it looks
like its from the devel list. I originally subscribed to this list in Feb.
2015. I must have been evicted. Not sure why. I've re-subscribed. I'll try
not to get booted again.

>> The second issue I ran into:
>>
>> function f(x, y: integer): float;
>> begin
>>       result:=float(dy)/float(dx)
>> end;
>>
>> When attempting to compile this it tells me that "float" is undefined. I
>> think I'm missing something here. "float" is the native Java name for
>> their
>> base floating point type and its a valid type for FPC. If I use "single"
>> instead it will compile. Seems odd.
> I can't comment the first part, but where exactly is a type named "float"
> defined in FPC (which unit)? E.g. single is defined in unit System and
> thus available for all FPC programs automatically. If some unit defines
> "float" (not sure about that, but it might be the case). I can see the
> System unit for Java defining "jfloat" as an alias to single - maybe you
> meant that one?
>
> Hope this helps
Yes, you're right. Sorry too many languages to deal with. And working in
this quasi-java-fpc world is bending my brain. So to sum up:

   fpc doesn't have a float type.
   Java does. Since its in the "java" namespace its named "Jfloat" in FPC.
   The native FPC equivalent is single.

THX - Jon

--
Sent from my Debian Linux laptop -- http://www.debian.org/intro/about

Jon Foster
JF Possibilities, Inc.
[hidden email]
541-410-2760
Making computers work for you!

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

leledumbo
Administrator
In reply to this post by Jon Foster
> The first issue I ran into is this:
>
> procedure Cppp1Activity.onResume;
> begin
>      inherited onResume;
>      with AAAlertDialog.InnerBuilder(self) do begin
>          setTitle(R.strings.app_name);
>      end;
> end;

I don't check by running the code directly, but looking at the source code:

  AAAlertDialog = class external 'android.app' name 'AlertDialog' (AADialog, ACDialogInterface)
  public
    type
      InnerBuilder = class;
      Arr1InnerBuilder = array of InnerBuilder;
      Arr2InnerBuilder = array of Arr1InnerBuilder;
      Arr3InnerBuilder = array of Arr2InnerBuilder;
      InnerBuilder = class external 'android.app' name 'Builder' (JLObject)

InnerBuilder doesn't look like anything callable.

Reading the offical reference (https://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog), I guess you need to instantiate it first and only then call its methods:

var
  Builder: AAAlertDialog.InnerBuilder;
  Dialog: AAAlertDialog;
...
  Builder := AAAlertDialog.InnerBuilder.Create(Self); // inside any Cppp1Activity method so Self refers to Cppp1Activity instance
  Dialog := Builder.setTitle(R.strings.app_name).create_; // note the '_'

> When attempting to compile this it tells me that "float" is undefined. I
> think I'm missing something here. "float" is the native Java name for their
> base floating point type and its a valid type for FPC. If I use "single"
> instead it will compile. Seems odd.

Pascal's Single maps to Java's float. There's another float type defined in Math unit but that's created for the routines inside the unit. Java's primitive type is not available in FPC JVM, use Pascal's type after mapping from Java. The class version (which should automatically (un)box) is available, though. So if you insist, simply use JLFloat.
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

noreply
In reply to this post by Jon Foster
On Sat, January 7, 2017 10:09 am, Jon Foster wrote:

> On 01/07/2017 03:06 AM, Tomas Hajny wrote:
>
>> On Sat, January 7, 2017 03:12, Jon Foster wrote:
>>
>>
>>
>> Hello,
>>
>>
>> You didn't mention that you weren't subscribed to the list, but since
>> this seemed to be the case, I included your address in Cc:.
> Thanks for this. I get a lot of mail from the FPC lists ... but it looks
> like its from the devel list. I originally subscribed to this list in Feb.
>  2015. I must have been evicted. Not sure why. I've re-subscribed. I'll
> try not to get booted again.
>>> The second issue I ran into:
>>>
>>>
>>> function f(x, y: integer): float; begin result:=float(dy)/float(dx)
>>> end;
>>>
>>> When attempting to compile this it tells me that "float" is
>>> undefined. I think I'm missing something here. "float" is the native
>>> Java name for
>>> their base floating point type and its a valid type for FPC. If I use
>>> "single"
>>> instead it will compile. Seems odd.
>> I can't comment the first part, but where exactly is a type named
>> "float"
>> defined in FPC (which unit)? E.g. single is defined in unit System and
>> thus available for all FPC programs automatically. If some unit defines
>>  "float" (not sure about that, but it might be the case). I can see the
>>  System unit for Java defining "jfloat" as an alias to single - maybe
>> you meant that one?
>>
>> Hope this helps
>>
> Yes, you're right. Sorry too many languages to deal with. And working in
> this quasi-java-fpc world is bending my brain.

This is one of the main reasons, I'm afraid of things like jvm/llvm and
even objectivefpc macOS mode because your brain starts juggling multiple
ideologies.. and your brain must have a modeswitch that is fuzzy (not
always switched in one mode, sometimes several) ;-)

> So to sum up:
>
> fpc doesn't have a float type. Java does. Since its in the "java"
> namespace its named "Jfloat" in FPC. The native FPC equivalent is single.
>

Well, fpc has Math unit which has float related tools and type that is not
quite the same. But as another poster said, that float in math unit
doesn't match up  to Java's
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Sven Barth-2
In reply to this post by Jon Foster
On 07.01.2017 03:12, Jon Foster wrote:

> I've been working on building an app for Android using the FPC's JVM
> target. I'm using fpc 3.0.0. I've run into a couple of things that I'm
> not sure if they're bugs or I just don't know what I'm doing. I was
> using fpc to avoid having to learn Java and have discovered that's not
> entirely possible. :-/
>
> The first issue I ran into is this:
>
> procedure Cppp1Activity.onResume;
> begin
>     inherited onResume;
>     with AAAlertDialog.InnerBuilder(self) do begin
>         setTitle(R.strings.app_name);
>     end;
> end;
>
> Cppp1Activity is a descendant of AAActivity. I'm overriding the onResume
> method. The problem I ran into was with the AAAlertDialog.InnerBuilder
> class. I can create an object of that class without incident. However if
> I try to call any of the methods (tried several) I get a "Class Cast"
> exception reported in the Android log and the app goes *poof*. I also
> tried just chaining the call like
> "AAAlertDialog.InnerBuilder(self).setTitle(R.strings.app_name);", and I
> tried this in the "Activity.onCreate" method with the same result. And
> yes "R.strings.app_name" points to an actual resource and I generated a
> "resources.pas" with the "R" class fresh for this test.

Here's what I had done in my Android application way back at Christmas
2011 (
http://lists.lazarus-ide.org/pipermail/lazarus/2011-December/134414.html ):

=== code begin ===

function TTrainTypeActivity.onCreateDialog(aID: jint): AADialog;
var
  builder: AAAlertDialog.InnerBuilder;
begin
  case aID of
    DialogIDDelete: begin
      builder := AAAlertDialog.InnerBuilder.Create(Self);

      builder.setMessage(JLString('Are you sure you want to delete train ' +
        'type ''' + fDataHelper.NameOfTrainType[fSelectedID] + '''?'));

      builder.setPositiveButton(JLString('Yes'), Self);
      builder.setNegativeButton(JLString('No'), Self);

      Result := builder.create_;
    end;
    else
      Result := Nil;
  end;
end;

=== code end ===

I know it's onCreateDialog() and not onResume(), but it should be the
same principle.

Though doesn't an activity itself already have a setTitle() method? At
least that's what I had used in my onCreate()...

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Jon Foster
In reply to this post by leledumbo
On 01/07/2017 10:39 AM, leledumbo wrote:

>> The first issue I ran into is this:
>>
>> procedure Cppp1Activity.onResume;
>> begin
>>       inherited onResume;
>>       with AAAlertDialog.InnerBuilder(self) do begin
>>           setTitle(R.strings.app_name);
>>       end;
>> end;
> I don't check by running the code directly, but looking at the source code:
>
>    AAAlertDialog = class external 'android.app' name 'AlertDialog' (AADialog,
> ACDialogInterface)
>    public
>      type
>        InnerBuilder = class;
>        Arr1InnerBuilder = array of InnerBuilder;
>        Arr2InnerBuilder = array of Arr1InnerBuilder;
>        Arr3InnerBuilder = array of Arr2InnerBuilder;
>        InnerBuilder = class external 'android.app' name 'Builder' (JLObject)
>
> InnerBuilder doesn't look like anything callable.
>
> Reading the offical reference
> (https://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog), I
> guess you need to instantiate it first and only then call its methods:
>
> var
>    Builder: AAAlertDialog.InnerBuilder;
>    Dialog: AAAlertDialog;
> ...
>    Builder := AAAlertDialog.InnerBuilder.Create(Self); // inside any
> Cppp1Activity method so Self refers to Cppp1Activity instance
>    Dialog := Builder.setTitle(R.strings.app_name).create_; // note the '_'
Thanks! Yes, you're right. I'm having a hard time understanding how the FPC
semantics fit the Java semantics. This is complicated because I'm trying to
learn Android, and to some extent, by extension, I'm getting forced into
Java too. So I'm real unclear about what all the Java examples I'm seeing
are actually doing. Been working with "object pascal" since Delphi 1/2. :-)

So the take away I see here is that I have to remember to use
class.create(...) to create objects from any Java class, not just FPC ones.

So that leaves me with the question: What about destructors? Must I call
free/destroy on all objects I create, or do they self-destruct? If so
destroy or free? From what I've seen of Java everything self destructs,
probably when a usage count hits 0. But I don't know. Perhaps calling
"destroy" is needed to release my claim on it? I was going to try calling
it and see if it blows. :-D

Yes, I figured out "create_" just as I figured out "InnerBuilder", instead
of "Builder". Not sure why that name was changed. I've learned I need to
cross reference the Android docs back to androidr14.inc & pas.

>> When attempting to compile this it tells me that "float" is undefined. I
>> think I'm missing something here. "float" is the native Java name for
>> their
>> base floating point type and its a valid type for FPC. If I use "single"
>> instead it will compile. Seems odd.
> Pascal's Single maps to Java's float. There's another float type defined in
> Math unit but that's created for the routines inside the unit. Java's
> primitive type is not available in FPC JVM, use Pascal's type after mapping
> from Java. The class version (which should automatically (un)box) is
> available, though. So if you insist, simply use JLFloat.
Yes, thank you. Tomas set me straight on this.

--
Jon Foster
JF Possibilities, Inc.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Jon Foster
In reply to this post by Sven Barth-2
On 01/08/2017 02:57 AM, Sven Barth wrote:

> On 07.01.2017 03:12, Jon Foster wrote:
>> I've been working on building an app for Android using the FPC's JVM
>> target. I'm using fpc 3.0.0. I've run into a couple of things that I'm
>> not sure if they're bugs or I just don't know what I'm doing. I was
>> using fpc to avoid having to learn Java and have discovered that's not
>> entirely possible. :-/
>>
>> The first issue I ran into is this:
>>
>> procedure Cppp1Activity.onResume;
>> begin
>>      inherited onResume;
>>      with AAAlertDialog.InnerBuilder(self) do begin
>>          setTitle(R.strings.app_name);
>>      end;
>> end;
>>
>> Cppp1Activity is a descendant of AAActivity. I'm overriding the onResume
>> method. The problem I ran into was with the AAAlertDialog.InnerBuilder
>> class. I can create an object of that class without incident. However if
>> I try to call any of the methods (tried several) I get a "Class Cast"
>> exception reported in the Android log and the app goes *poof*. I also
>> tried just chaining the call like
>> "AAAlertDialog.InnerBuilder(self).setTitle(R.strings.app_name);", and I
>> tried this in the "Activity.onCreate" method with the same result. And
>> yes "R.strings.app_name" points to an actual resource and I generated a
>> "resources.pas" with the "R" class fresh for this test.
> Here's what I had done in my Android application way back at Christmas
> 2011 (
> http://lists.lazarus-ide.org/pipermail/lazarus/2011-December/134414.html ):
>
> === code begin ===
>
> function TTrainTypeActivity.onCreateDialog(aID: jint): AADialog;
> var
>    builder: AAAlertDialog.InnerBuilder;
> begin
>    case aID of
>      DialogIDDelete: begin
>        builder := AAAlertDialog.InnerBuilder.Create(Self);
>
>        builder.setMessage(JLString('Are you sure you want to delete train ' +
>          'type ''' + fDataHelper.NameOfTrainType[fSelectedID] + '''?'));
>
>        builder.setPositiveButton(JLString('Yes'), Self);
>        builder.setNegativeButton(JLString('No'), Self);
>
>        Result := builder.create_;
>      end;
>      else
>        Result := Nil;
>    end;
> end;
>
> === code end ===
>
> I know it's onCreateDialog() and not onResume(), but it should be the
> same principle.
>
> Though doesn't an activity itself already have a setTitle() method? At
> least that's what I had used in my onCreate()...
>
> Regards,
> Sven
>
Yes, same principal. Since this is a one time in the lifetime of the app
use dialog I didn't see the point of building it into the onCreateDialog()
/ onPrepareDialog() methods. Its going to be shown the first time someone
launches my app and then never seen again unless uninstalled / reinstalled,
data erased, installed on another device, ...

What I don't quite get from your example is using "self" as the second
argument to setPositiveButton() & setNegativeButton. That parameter is
asking for an OnClickListener() class. When I tried that I received a
compile time error as I expected.

Yes, the AAActivity class has a "setTitle()" method. However it sets the
title for the activity. Where as the AAAlertDialog.InnnerBuilder.setTitle()
method sets a title on the dialog window. I actually decided I like it
better without, but I'm still experimenting.

THX - Jon

--
Jon Foster
JF Possibilities, Inc.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Sven Barth-2

Am 10.01.2017 06:06 schrieb "Jon Foster" <[hidden email]>:
> What I don't quite get from your example is using "self" as the second argument to setPositiveButton() & setNegativeButton. That parameter is asking for an OnClickListener() class. When I tried that I received a compile time error as I expected.

That's because in my case the activity also implements the corresponding interface, just ignore that ;)

> Yes, the AAActivity class has a "setTitle()" method. However it sets the title for the activity. Where as the AAAlertDialog.InnnerBuilder.setTitle() method sets a title on the dialog window. I actually decided I like it better without, but I'm still experimenting.

Okay.

Oh and regarding Free: on JVM garbage collection is used also with FPC.

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Michael Schnell
In reply to this post by Jon Foster
On 10.01.2017 05:13, Jon Foster wrote:
> On 01/07/2017 10:39 AM, leledumbo wrote:
>
> So that leaves me with the question: What about destructors? Must I
> call free/destroy on all objects I create, or do they self-destruct?
> If so destroy or free?

AFAIU, in fpc destroying any objects is mandatory. And this close to
always needs to be done with "Free" (which inside the class finally
calls Destroy).

If destroying an object is not necessary, the class should provide a
dummy Free procedure. So the application programmer always can/should
use Free.

-Michael
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Sven Barth-2

Am 11.01.2017 08:54 schrieb "Michael Schnell" <[hidden email]>:
>
> On 10.01.2017 05:13, Jon Foster wrote:
>>
>> On 01/07/2017 10:39 AM, leledumbo wrote:
>>
>> So that leaves me with the question: What about destructors? Must I call free/destroy on all objects I create, or do they self-destruct? If so destroy or free?
>
>
> AFAIU, in fpc destroying any objects is mandatory. And this close to always needs to be done with "Free" (which inside the class finally calls Destroy).
>
> If destroying an object is not necessary, the class should provide a dummy Free procedure. So the application programmer always can/should use Free.

We're talking about JVM here where garbage collections *must* be used. So FPC does as well for that target.

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Jon Foster
On 01/11/2017 02:25 AM, Sven Barth wrote:

>
> Am 11.01.2017 08:54 schrieb "Michael Schnell" <[hidden email]
> <mailto:[hidden email]>>:
> >
> > On 10.01.2017 05:13, Jon Foster wrote:
> >>
> >> On 01/07/2017 10:39 AM, leledumbo wrote:
> >>
> >> So that leaves me with the question: What about destructors? Must I
> call free/destroy on all objects I create, or do they self-destruct? If
> so destroy or free?
> >
> >
> > AFAIU, in fpc destroying any objects is mandatory. And this close to
> always needs to be done with "Free" (which inside the class finally calls
> Destroy).
> >
> > If destroying an object is not necessary, the class should provide a
> dummy Free procedure. So the application programmer always can/should use
> Free.
>
> We're talking about JVM here where garbage collections *must* be used. So
> FPC does as well for that target.
>
It goes against soooo many years of working with Object Pascal... but I'll
let the JVM destroy them.

Thanks!

--
Jon Foster
JF Possibilities, Inc.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Michael Schnell
In reply to this post by Sven Barth-2
On 11.01.2017 11:25, Sven Barth wrote:
>
> We're talking about JVM here where garbage collections *must* be used.
> So FPC does as well for that target.
>
This of course is true. But if the class code is in fpc, fpc paradigms
should be adhered, as well. and here the fpc code *can* e.g. explicitly
allocate stuff that needs to be freed later, or e.g. can open a
connection to whatever that needs to be closed later, and so (if not
using ref counted objects) with such classes destroy() needs to be
called (via the free()  chain).

Regarding this, IMHO it would be good practice to always provide destroy
and free, and if it's empty it does not harm to call it.

-Michael
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

noreply
On Thu, January 12, 2017 2:08 am, Michael Schnell wrote:

> On 11.01.2017 11:25, Sven Barth wrote:
>
>>
>> We're talking about JVM here where garbage collections *must* be used.
>> So FPC does as well for that target.
>>
>>
> This of course is true. But if the class code is in fpc, fpc paradigms
> should be adhered, as well. and here the fpc code *can* e.g. explicitly
> allocate stuff that needs to be freed later, or e.g. can open a connection
> to whatever that needs to be closed later, and so (if not using ref
> counted objects) with such classes destroy() needs to be called (via the
> free()  chain).
>
> Regarding this, IMHO it would be good practice to always provide destroy
> and free, and if it's empty it does not harm to call it.
>

What if you are porting code to a non jvm... if you copy and paste
something and it has no free, you're screwed.

i.e. say you have some JVM algorithms that now need to be used in win32 or
bsd using the regular fpc compilation.... can't port them without
inspecting the code carefully for missing free's


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Michael Schnell
On 14.01.2017 20:36, Lars wrote:
> What if you are porting code to a non jvm... if you copy and paste
> something and it has no free, you're screwed.
Sorry. I don't understand. AFAIK, in a non jvm project, free() always is
provided (and used).
> i.e. say you have some JVM algorithms that now need to be used in win32 or
> bsd using the regular fpc compilation.... can't port them without
> inspecting the code carefully for missing free's
>

IMHOP, JVM based (or any other) pascal classes, that does not provide
free() - even if dummy - simply should not exist.

-Michael
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

noreply
On Mon, January 16, 2017 2:40 am, Michael Schnell wrote:
> On 14.01.2017 20:36, Lars wrote:
>
>> What if you are porting code to a non jvm... if you copy and paste
>> something and it has no free, you're screwed.
> Sorry. I don't understand. AFAIK, in a non jvm project, free() always is
> provided (and used).

If you have a jvm project with lots of code and now want to start using
this code in another regular mode objfpc unix/win32 application...

Sorry I'm not familiar with the jvm fpc project (I have been meaning to
try it).

Delphi has some similar issues with garbage collected iOS development
where they have provided some fake release/free system to try solve the
issue, which, has the side effect of making garbage collected programming
much like non garbage collected programming which in a way defeats the
purpose..

i.e. if you have a fake free procedure that can be called, then why
program in garbage collection in the first place..
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

wkitty42
On 01/17/2017 01:07 PM, Lars wrote:
> i.e. if you have a fake free procedure that can be called, then why program
> in garbage collection in the first place..

can you not IFDEF it so that it does actual work in a non-garbage collecting
environment? seems to be the obvious answer there...

--
  NOTE: No off-list assistance is given without prior approval.
        *Please keep mailing list traffic on the list* unless
        private contact is specifically requested and granted.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Michael Schnell
In reply to this post by noreply
On 17.01.2017 19:07, Lars wrote:
> If you have a jvm project with lots of code and now want to start using
> this code in another regular mode objfpc unix/win32 application...
Exactly this as the point I wanted to express. Even when coding an fpc
application or library for use with  jvm, free (and destroy) should be
used and provided in the normal way good old Object Pascal requires. If
jvm does garbage collection under the hood  (and not momentarily adheres
to free, as we are used to with Object Pascal) this should be handled as
a hidden implementation detail and as little as possible be communicated
outside, so that  using this code in another regular mode objfpc
unix/win32 application can be done as seamlessly as possible .

-Michael
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ppcjvm issues

Jon Foster
On 01/18/2017 01:16 AM, Michael Schnell wrote:

> On 17.01.2017 19:07, Lars wrote:
>> If you have a jvm project with lots of code and now want to start using
>> this code in another regular mode objfpc unix/win32 application...
> Exactly this as the point I wanted to express. Even when coding an fpc
> application or library for use with  jvm, free (and destroy) should be
> used and provided in the normal way good old Object Pascal requires. If
> jvm does garbage collection under the hood (and not momentarily adheres
> to free, as we are used to with Object Pascal) this should be handled as
> a hidden implementation detail and as little as possible be communicated
> outside, so that using this code in another regular mode objfpc
> unix/win32 application can be done as seamlessly as possible .

I agree for seamless compatibility "free" / "destroy" should be provided.
As far as I can tell the JVM implementation of TObject does provide these.
Using the native Java/Android objects is a lot like using Lazarus / Delphi
/ TComponent based classes. You create them and whoever you specify as the
owner frees them. In this case the JVM is freeing them. But that's not a
detail I need concern myself with.

That said, all of the code in my project was written and tested in plain
old native compiled code running on my Linux box. Only the UI code is
unique to Android. As such I've not run into any problems creating and
freeing my native FPC based components. I haven't tried freeing/destroying
Java/Android components. I imagine its going to tell me that those methods
don't exist on those objects, since those class libraries don't provide
them. But maybe FPC has hidden that detail as well. When I get a moment
I'll give it a whirl, 'cause I've had many years of training to free what I
create. I started my Pascal journey with Delphi 1/2 in '96.

THX - Jon

--
Sent from my Debian Linux workstation -- http://www.debian.org/intro/about

Jon Foster
JF Possibilities, Inc.
[hidden email]
541-410-2760
Making computers work for you!

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
12