First some code improvements to avoid future headaches:
- 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.
- 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;
- 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!
Without the error log it is difficult to know.
– Valdeir Psr
The problem is that mine and the xe7....
– Leandro Silva
You do not have access to the device’s Logcat or emulator?
– Valdeir Psr
Has not android studio bugo the android folder-sdk will have to download everything d new
– Leandro Silva
You have no Tedit Onchange event command?
– Cleber Griff
don’t have no...have an idea what might be...?
– Leandro Silva
put the Code!
– Edu Mendonça
The code is very simple...there is nothing abnormal...but all help is welcome..!!!!
– Leandro Silva
I realized so far the problem is in changing the focus of edit1 to other.....
– Leandro Silva