[fpc-pascal] ppcjvm issues
Sven Barth
pascaldragon at googlemail.com
Sun Jan 8 11:57:52 CET 2017
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
More information about the fpc-pascal
mailing list