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  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to