[fpc-pascal] ppcjvm issues
Jon Foster
jon-lists at jfpossibilities.com
Tue Jan 10 05:13:56 CET 2017
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.
More information about the fpc-pascal
mailing list