Why does the app close when I click edit1?

Asked

Viewed 403 times

2

Guys the problem is this, I click on the button to create a new form ,edit1 gets the focus, digital keyboard appears when I click on the letter a for example the app closes, why is it? Anyone can help..?

procedure Tformadhor.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  action := TCloseAction.caFree;
  formadhor:=nil;
  formrel.somarel(usua.Id);
  formrel.Show;
end;

procedure Tformadhor.FormShow(Sender: TObject);
begin
  edpub.SetFocus;
end;

procedure Tformadhor.Rectangle3Click(Sender: TObject);
begin
  close;
end;

procedure Tformadhor.Rectangle5Click(Sender: TObject);
begin
  salvareg;
  MultiView1.HideMaster;
end;

procedure Tformadhor.salvareg;
var 
  reg:TRegrel;
  db:TDM2;
begin
  reg:=TRegrel.create('null',m,y,strtoint(edpub.Text),strtoint(editvid.Text),
    edithora.Text,strtoint(editrev.Text),strtoint(editest.Text));
  db:=TDM2.Create(nil);
  if db.salvareg(usua,reg) then
    Showmessage('Salvo com Sucesso!!');
  db.DisposeOf;
end;

procedure Tformadhor.setusu(usu: TUsuario; nomemes: string; mes, ano: Integer);
begin
  Labnome.Text:=usu.nomecomp;
  labmes.Text:=nomemes;
  usua:=TUsuario.create('clone','','','',0);
  usua.clone(usu);
  m:=mes;
  y:=ano;
end;
  • Without the error log it is difficult to know.

  • The problem is that mine and the xe7....

  • You do not have access to the device’s Logcat or emulator?

  • Has not android studio bugo the android folder-sdk will have to download everything d new

  • You have no Tedit Onchange event command?

  • don’t have no...have an idea what might be...?

  • put the Code!

  • The code is very simple...there is nothing abnormal...but all help is welcome..!!!!

  • I realized so far the problem is in changing the focus of edit1 to other.....

Show 4 more comments

2 answers

2


You need a Hotfix for the compiler, very likely that the JNI being used does not support the version of Android that this generating.

Hotfix depends on the version of Delphi you are using and also the version of Android you want to build.

Source

  • 1

    This is a real possibility. See if you can get Delphi XE7 Update 1 or some Hotfix, which should help!

  • Does anyone know who has Arq downloaded can not download from the shipper....

  • That’s right.... I updated and stayed 10/10... Thank you...

1

First some code improvements to avoid future headaches:

  1. If you use firemonkey, from here:
procedure Tformadhor.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  action := TCloseAction.caFree;
  formadhor:=nil;
  formrel.somarel(usua.Id);
  formrel.Show;
end;

It would be so much simpler just to do it like this:

procedure Tformadhor.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  formrel.somarel(usua.Id);
  formrel.Show;

  Self.close;
end;

If Thread hangs at this point, as the method has already been triggered, your app will simply close without any error. You better not put any code in this event and make this call to another form by informing the ID through some other method, for example:

procedure geraRelatorio(pID: integer);
begin
  if not Assigned(formrel) then
    Application.CreateForm(Tformrel, formrel);
  formrel.somarel(pID);
  formrel.Show;
  Self.Close;
end;

Since Firemonkey is an interface-oriented framework, the simple call to the onClose or onCloseQuery method already activates the destructor TObject.destroy that you set the interface reference to be destroyed, because it’s out of scope. Only do not destroy it if it is attached to a form that is the main form of the application.

  1. Each method below has Memory Leak:
procedure Tformadhor.salvareg;
var 
  reg:TRegrel;
  db:TDM2;
begin
  reg:=TRegrel.create('null',m,y,strtoint(edpub.Text),strtoint(editvid.Text),
    edithora.Text,strtoint(editrev.Text),strtoint(editest.Text));
  db:=TDM2.Create(nil);
  if db.salvareg(usua,reg) then
    Showmessage('Salvo com Sucesso!!');
  db.DisposeOf;
end;

procedure Tformadhor.setusu(usu: TUsuario; nomemes: string; mes, ano: Integer);
begin
  Labnome.Text:=usu.nomecomp;
  labmes.Text:=nomemes;
  usua:=TUsuario.create('clone','','','',0);
  usua.clone(usu);
  m:=mes;
  y:=ano;
end;

Let’s go in pieces - (Jack ~1980):

procedure Tformadhor.salvareg;
var 
  reg: TRegrel;
  db: TDM2;
begin
// Encontrei um descendente de JAVA aqui gente! Construtor amarrado é coisa de JAVAicano
  reg := TRegrel.create('null', m, y, strtoint(edpub.Text), strtoint(editvid.Text),
    edithora.Text, strtoint(editrev.Text), strtoint(editest.Text));
  db := TDM2.Create(nil);
  try
    if db.salvareg(usua, reg) then
      Showmessage('Salvo com Sucesso!!');
  finally
    db.DisposeOf;
    reg.DisposeOf;
  end;
end;
procedure Tformadhor.setusu(usu: TUsuario; nomemes: string; mes, ano: Integer);
begin
  Labnome.Text := usu.nomecomp;
  labmes.Text := nomemes;
  // Mais uma ocorrência JAVAicana aqui
  usua := TUsuario.create('clone','','','',0);
  try
  { usua não tá definido aqui no escopo do método, se for uma propriedade da
classe, será eliminado juntamente do form, porém se for uma var você quem precisa
matar a instância criada em runtime }
  //usua.clone(usu);
  { Porém, ao simplesmente passar o ponteiro de um objeto para outro, como é o 
caso abaixo, você pode eliminar o objeto usua ou usu uma vez que os 2 representam
a mesma coisa, então ao eliminar um deles, você está liberando a memória pra
todas as instâncias onde aquele setor de memória foi usado }
    usua := usu;
    // faz alguma coisa com o usuario
    m := mes;
    y := ano;
  finally
    usua.DisposeOf;
  end;
end;
  1. Now that we’ve improved the code of what you’ve shared, according to the steps you’ve taken, this code here is where the hang of its application:
procedure Tformadhor.FormShow(Sender: TObject);
begin
  edpub.SetFocus;
end;

But only set focus for a control does not cause problems, would have to confirm if your DIT does not have some event onTyping, onChange, onEnter, onExit, onMouseMove, onMouseDown which are events that occur simultaneously in the main thread, depending on the device and what you put in those events, your application simply aborts. If there is an event at these points, be sure to use Threads to call these methods because then you can avoid possible abortions from the application.

Always avoid processing on mobile, try to leave the processing of anything to the back end, on mobile do simple things, light things, your user thanks for this!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.