Fórum Erro ao encerrar aplicativo #449902

30/07/2013

0

Meus amigos, tenho um Timer no form Principal com o seguinte código:

var
  hora : TDateTime;
begin
  stsMensagens.Panels[1].Text := TimeToStr(Time);


No evento onShow do Principal tenho o seguinte:

var
  hora : TDateTime;
begin

  hora := Time;

  if (hora >= strtotime('00:00')) and (hora <= strtotime('11:59')) then
     stsMensagens.Panels[2].Text:=' Bom Dia, '+ frmPrincipal.UserControl1.CurrentUser.UserName +'. Bom Serviço! ©2012 - Todos os direitos resevados';

  if (hora >= strtotime('12:00')) and (hora <= strtotime('17:59')) then
     stsMensagens.Panels[2].Text:=' Boa Tarde, '+ frmPrincipal.UserControl1.CurrentUser.UserName +'. Bom Serviço! ©2012 - Todos os direitos resevados';

  if (hora >= strtotime('18:00')) and (hora <= strtotime('23:59')) then
     stsMensagens.Panels[2].Text:=' Boa Noite, '+ frmPrincipal.UserControl1.CurrentUser.UserName +'. Bom Serviço! ©2012 - Todos os direitos resevados';


E no Sair tenho:
  Application.Terminate;


Ao logar e depois clicar em Sair, está dando erro de Access Violation. Não sei o motivo.
Frederico Brigatte***

Frederico Brigatte***

Responder

Posts

30/07/2013

Frederico Brigatte***

No Close está assim:

procedure TfrmPrincipal.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := caNone;
end;


No Activate está assim:

procedure TfrmPrincipal.FormActivate(Sender: TObject);
begin
 stsMensagens.Panels.Items[0].Text := formatdatetime(' dddd", "dd" de "mmmm " de "yyyy', Now);
 stsMensagens.Panels.Items[1].Text := formatdatetime(' hh:mm:ss', Now);
end;
Responder

Gostei + 0

30/07/2013

Frederico Brigatte***

Correção: No Timer, está assim:

procedure TfrmPrincipal.Timer1Timer(Sender: TObject);
var
  hora : TDateTime;
begin
  stsMensagens.Panels[1].Text := TimeToStr(Time);

  hora := Time;

  if (hora >= strtotime('00:00')) and (hora <= strtotime('11:59')) then
     stsMensagens.Panels[2].Text:=' Bom Dia, '+ frmPrincipal.UserControl1.CurrentUser.UserName +'. Bom Serviço! ©2012 - Todos os direitos resevados';

  if (hora >= strtotime('12:00')) and (hora <= strtotime('17:59')) then
     stsMensagens.Panels[2].Text:=' Boa Tarde, '+ frmPrincipal.UserControl1.CurrentUser.UserName +'. Bom Serviço! ©2012 - Todos os direitos resevados';

  if (hora >= strtotime('18:00')) and (hora <= strtotime('23:59')) then
     stsMensagens.Panels[2].Text:=' Boa Noite, '+ frmPrincipal.UserControl1.CurrentUser.UserName +'. Bom Serviço! ©2012 - Todos os direitos resevados';
end;
Responder

Gostei + 0

30/07/2013

Wilton Júnior

Fred na boa
o que vc acha disso
ar
hora : TDateTime;
begin

hora := Time;

if (hora >= strtotime('00:00')) and (hora <= strtotime('11:59')) then
stsMensagens.Panels[2].Text:=' Bom Dia ';
if (hora >= strtotime('12:00')) and (hora <= strtotime('17:59')) then
stsMensagens.Panels[2].Text:=' Boa Tarde ';

if (hora >= strtotime('18:00')) and (hora <= strtotime('23:59')) then
stsMensagens.Panels[2].Text:=' Boa Noite ';

stsMensagens.Panels[2].Text:= stsMensagens.Panels[2].Text+ frmPrincipal.UserControl1.CurrentUser.UserName +'. Bom Serviço! ©2012 - Todos os direitos resevados';

ondde vc colocou essa appliation terminate;
Responder

Gostei + 0

30/07/2013

Frederico Brigatte***

No Menu Sair. Ai da o erro.
Responder

Gostei + 0

30/07/2013

Francisco Macário

Já tentou parar o Time antes de finalizar a App.
Responder

Gostei + 0

30/07/2013

Frederico Brigatte***

Como seria isso? Seria no menu sair?
Responder

Gostei + 0

30/07/2013

Francisco Macário

Como seria isso? Seria no menu sair?


Timer1.Enabled := false;

Inclua no OnClose do Form principal.


Responder

Gostei + 0

30/07/2013

Frederico Brigatte***

Imaginei que fosse isso, só não sabia onde colocar. Vou testar.
Responder

Gostei + 0

30/07/2013

Frederico Brigatte***

Só para informação, estou usando UserControl.
Responder

Gostei + 0

30/07/2013

Frederico Brigatte***

No evento do menu sair, coloquei:


frmPrincipal.UserControl1.Destroy;
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar