Recent

Author Topic: Problema com herança de formulario  (Read 2366 times)

StraightFree

  • New Member
  • *
  • Posts: 38
Problema com herança de formulario
« on: March 12, 2020, 04:47:02 pm »
Olá pessoal,

Mais uma vez solicito a ajuda de vocês para resolver um problema.

Vamos ao problema:

Possuo um formPadrao, nele defino o tamanho padrao dos meus formularios alem das cores e outros detalhes.

Desse formulário eu herdo outro formulário que é um formCadastroPadrao.
Nesse formulário, possuo um TDataSource e nele tenho associado dois eventos onDataChange e onStateChange.

Deste formulario eu herdo todos os formulario de cadastro do meu sistema.

Tambem tenho um formPrincipal (que herda do formPadrao), que é responsavel por chamar os formularios de cadastro.

E tudo funciona perfeitamente.

Abro o sistema, acesso as telas de cadastro e tudo funciona. O problema ocorre quando fecho a aplicação pelo formPrincipal. Faço um:

Code: Pascal  [Select][+][-]
  1. Application.Terminate;
  2.  

Por algum motivo, que ainda não identifiquei é executado o evento onStateChange do formCadastroPadrao uma vez para cada formulário de cadastro aberto (se eu abrir 10 vezes o formCadastroPessoa, o evento será executado 10 vezes).
Ai nesse momento, acaba dando o seguinte erro:

Code: Pascal  [Select][+][-]
  1. Project Teste raised exception class 'External: SIGSEGV'.


Estou fazendo algo errado ao utilizar a herança?

Alguem tem alguma sugestão do que pode estar causando o problema?

Qualquer ajuda seŕa muito bem vinda.

Obrigado!

Handoko

  • Hero Member
  • *****
  • Posts: 5537
  • My goal: build my own game engine using Lazarus
Re: Problema com herança de formulario
« Reply #1 on: March 12, 2020, 05:14:58 pm »
Translated using Google Translate:
Quote
Hello people,

Once again I ask for your help in solving a problem.

Let's get to the problem:

I have a standard form, in it I define the standard size of my forms in addition to colors and other details.

From this form I inherit another form which is a standard formCadastroPadrao.
In this form, I have a TDataSource and I have two events associated with it onDataChange and onStateChange.

From this form I inherit all the registration forms from my system.

I also have a formPrincipal (which inherits from the Standard form), which is responsible for calling the registration forms.

And everything works perfectly.

I open the system, access the registration screens and everything works. The problem occurs when I close the application using formPrincipal. I do one:

...........................

For some reason, that I have not yet identified, the onStateChange event of the formCadastroPadrao is executed once for each open registration form (if I open the formCadastroPessoa 10 times, the event will be executed 10 times).
Then, it ends up giving the following error:

...........................

Am I doing something wrong when using inheritance?

Does anyone have any suggestions as to what may be causing the problem?

Any help is very welcome.

Thanks!

SIGSEGV error is one of the hardest to debug issue. This error happens because you do not handle the memory correctly, usually when using pointer type variable. Something like:

- Try to read/write data on the memory location you haven't allocated
- Try to access memory location that you shouldn't
- Your variable points to wrong memory location
- You use variable that hasn't initialized
- You call any object function before calling T_class_of_the_object.Create
- You forget freeing the object
- etc

Because there are too many possibilities and it is relative hard to solve, you should provide us the source code. If you're not willing to publicize the code, you can write a demo project that can show the issue.

Create a new folder, copy and paste all the necessary files except: the binary (exe file), *.bak, lib and backup folders. Compress the folder and send the zip here.

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Problema com herança de formulario
« Reply #2 on: March 12, 2020, 06:44:58 pm »
Kind regards.

 

TinyPortal © 2005-2018