首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >故障分割(11) Delphi手机

故障分割(11) Delphi手机
EN

Stack Overflow用户
提问于 2014-09-15 13:15:52
回答 1查看 2.6K关注 0票数 1
代码语言:javascript
运行
复制
unit Main;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.ListView.Types, IPPeerClient, System.Rtti, System.Bindings.Outputs,
  Fmx.Bind.Editors, Data.Bind.EngExt, Fmx.Bind.DBEngExt, Data.Bind.Components,
  REST.Client, Data.Bind.ObjectScope, FMX.StdCtrls, FMX.ListView, System.JSON, REST.types,
  FMX.Layouts, FMX.Memo, FMX.ListBox, REST.Json, FMX.Colors, FMX.Objects, gcmnotification,
  FMX.Edit;


type
  TForm1 = class(TForm)
    ToolBar1: TToolBar;
    ToolBar2: TToolBar;
    Label1: TLabel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    RESTClient1: TRESTClient;
    RESTRequest1: TRESTRequest;
    RESTResponse1: TRESTResponse;
    BindingsList1: TBindingsList;
    MemoContent: TMemo;
    LinkControlToFieldContent: TLinkControlToField;
    panel2: TPanel;
    ToolBar3: TToolBar;
    Label2: TLabel;
    btnExit: TSpeedButton;
    Label3: TLabel;
    email: TEdit;
    Label4: TLabel;
    Rectangle1: TRectangle;
    btnReg: TButton;
    popup: TRectangle;
    Label5: TLabel;
    btnOK: TColorButton;
    Label6: TLabel;
    procedure SpeedButton1Click(Sender: TObject);
    procedure Label5Click(Sender: TObject);
    procedure btnExitClick(Sender: TObject);
    procedure btnRegClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    gcmn: TGCMNotification;
  end;
const
  GCM_SENDERID = '460004329921';
  API_ID = 'AIzaSyBclEqDL-yFJRZZ6ESpBZLACJ27ROh7oao';
var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.btnExitClick(Sender: TObject);
begin
  FreeAndNil(Application);
end;

procedure TForm1.btnRegClick(Sender: TObject);
begin
 gcmn.SENDERID := GCM_SENDERID;
  if gcmn.doRegister then
  begin
    if email.Text='' then
      popup.Visible := true
    else
    begin
      RESTRequest1.Method := TRESTRequestMethod.rmPOST;
      RESTRequest1.AddParameter('type', 'register', TRESTRequestParameterKind.pkGETorPOST);
      RESTRequest1.AddParameter('regID', gcmn.RegistrationID, TRESTRequestParameterKind.pkGETorPOST);
      RESTRequest1.AddParameter('email', email.Text, TRESTRequestParameterKind.pkGETorPOST);
      RESTRequest1.Execute;
    end;
  end;
end;

procedure TForm1.Label5Click(Sender: TObject);
begin
  popup.Visible:=false;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  jValue:TJSONValue;
begin
  RESTRequest1.Method := TRESTRequestMethod.rmPOST;
  RESTRequest1.AddParameter('type', 'select', TRESTRequestParameterKind.pkGETorPOST);
  RESTRequest1.AddParameter('table_name', 'person', TRESTRequestParameterKind.pkGETorPOST);
  RESTRequest1.Execute;
  jValue:=RESTResponse1.JSONValue;
  MemoContent.Text := jValue.ToString;
end;
end.

当im试图运行程序时,它会将应用程序安装到模拟器,但应用程序没有启动。

我有个错误:

第一次机会例外为408839F8美元。异常类分割故障(11)。进程mClient.apk (1795年)

代码语言:javascript
运行
复制
unit gcmnotification;

interface
{$IFDEF ANDROID}
uses
  System.SysUtils,
  System.Classes,
  FMX.Helpers.Android,
  Androidapi.Helpers,
  Androidapi.JNI.PlayServices,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNIBridge,
  Androidapi.JNI.JavaTypes;

type
  TGCMNotificationMessageKind = (nmMESSAGE_TYPE_MESSAGE, nmMESSAGE_TYPE_DELETED, nmMESSAGE_TYPE_SEND_ERROR);

  { Discription of notification for Notification Center }
  TGCMNotificationMessage = class (TPersistent)
  private
    FKind: TGCMNotificationMessageKind;
    FSender: string;
    FWhat: integer;
    FBody: string;
  protected
    procedure AssignTo(Dest: TPersistent); override;
  public
    { Unique identificator for determenation notification in Notification list }
    property Kind: TGCMNotificationMessageKind read FKind write FKind;
    property Sender: string read FSender write FSender;
    property What: integer read FWhat write FWhat;
    property Body: string read FBody write FBody;
    constructor Create;
  end;

  TOnReceiveGCMNotification = procedure (Sender: TObject; ANotification: TGCMNotificationMessage) of object;

  TGCMNotification = class(TComponent)
  strict private
    { Private declarations }
    FRegistrationID: string;
    FSenderID: string;
    FOnReceiveGCMNotification: TOnReceiveGCMNotification;
    FReceiver: JBroadcastReceiver;
    FAlreadyRegistered: boolean;
    function CheckPlayServicesSupport: boolean;
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function DoRegister: boolean;
    function GetGCMInstance: JGoogleCloudMessaging;
  published
    { Published declarations }
    property SenderID: string read FSenderID write FSenderID;
    property RegistrationID: string read FRegistrationID write FRegistrationID;
    property OnReceiveGCMNotification: TOnReceiveGCMNotification read FOnReceiveGCMNotification write FOnReceiveGCMNotification;
  end;

{$ENDIF}
implementation
{$IFDEF ANDROID}
uses
  uGCMReceiver;


{ TGCMNotification }
function TGCMNotification.CheckPlayServicesSupport: boolean;
var
  resultCode: integer;
begin
  resultCode := TJGooglePlayServicesUtil.JavaClass.isGooglePlayServicesAvailable(SharedActivity);
  result := (resultCode = TJConnectionResult.JavaClass.SUCCESS);
end;

constructor TGCMNotification.Create(AOwner: TComponent);
var
  Filter: JIntentFilter;
begin
  inherited;
  Filter := TJIntentFilter.Create;
  FReceiver := TJGCMReceiver.Create(Self);
  SharedActivity.registerReceiver(FReceiver, Filter);
  FAlreadyRegistered := false;
end;

destructor TGCMNotification.Destroy;
begin
  SharedActivity.unregisterReceiver(FReceiver);
  FReceiver := nil;
  inherited;
end;

function TGCMNotification.DoRegister: boolean;
var
  p: TJavaObjectArray<JString>;
  gcm: JGoogleCloudMessaging;
begin
  if FAlreadyRegistered then
    result := true
  else
  begin
    if CheckPlayServicesSupport then
    begin
      gcm := GetGCMInstance;
      p := TJavaObjectArray<JString>.Create(1);
      p.Items[0] := StringToJString(FSenderID);
      FRegistrationID := JStringToString(gcm.register(p));
      FAlreadyRegistered := (FRegistrationID <> '');
      result := FAlreadyRegistered;
    end
    else
      result := false;
  end;
end;

function TGCMNotification.GetGCMInstance: JGoogleCloudMessaging;
begin
  result := TJGoogleCloudMessaging.JavaClass.getInstance(SharedActivity.getApplicationContext);
end;

{ TGCMNotificationMessage }

procedure TGCMNotificationMessage.AssignTo(Dest: TPersistent);
var
  DestNotification: TGCMNotificationMessage;
begin
  if Dest is TGCMNotificationMessage then
  begin
    DestNotification := Dest as TGCMNotificationMessage;
    DestNotification.Kind := Kind;
    DestNotification.What := What;
    DestNotification.Sender := Sender;
    DestNotification.Body := Body;
  end
  else
    inherited AssignTo(Dest);
end;

constructor TGCMNotificationMessage.Create;
begin
  Body := '';
end;
{$ENDIF}
end.

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-15 13:44:54

也许还有更多的问题,但最明显的问题是:

  1. 您不实例化gcmn
  2. 不能显式销毁Application对象。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25849012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档