Erro ao focar em um controle ou janela

183 views
Skip to first unread message

valt...@valtecom.com.br

unread,
Nov 18, 2025, 6:40:04 AMNov 18
to Harbour Minigui
Good morning friends of the group,
I'm facing a strange problem in a system, in a product sales function. Sometimes an error occurs when the system tries to focus on a control, saying that the control doesn't exist or that the window isn't active, but it's the product sales window. It runs normally for hours and then, at a random moment, the error appears, but usually after a few hours of use.
One detail that I believe is worth mentioning is that the system in question has its executable on a PC that functions as a server and is accessed via a shortcut. I don't know if this is relevant, because in most of my systems I have an executable on each PC and only access the data on the server PC, and in those cases these random errors don't occur.
I will post the error log excerpt below; perhaps it will be more enlightening than what I described.

Thank you.

Valteçom
Uberaba MG Brazil.

Errorlog.htm returned
Date: 14/11/2025 Time: 16:31:57
Application: \\server\SISTEMAS\SGC_NOV\WSGCPDV.EXE
User: CAIXA1 / win10
Time from start: 0 days 0 hours 35 mins 23 secs
Error MGERROR/0 Window: janelabuscaprodutos is not active. Program terminated.

--------------------------------- Stack Trace ---------------------------------
Called from MSGMINIGUIERROR(0)
Called from _RELEASEWINDOW(0)
Called from DOMETHOD(0)
Called from WN_SELECIONAPRODUTOS(1403) in module: VENDAS.PRG

Jackson Santos

unread,
Nov 18, 2025, 6:54:54 AMNov 18
to valt...@valtecom.com.br, Harbour Minigui
Bom dia
Eu enfrento o mesmo problema, nunca consegui a solução, do nada dar um erro inexplicável.

--
Visit our website on https://www.hmgextended.com/ or https://www.hmgextended.org/
---
You received this message because you are subscribed to the Google Groups "Harbour Minigui" group.
To unsubscribe from this group and stop receiving emails from it, send an email to minigui-foru...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/minigui-forum/9e81da29-9c01-4309-a222-b53d6460e7d0n%40googlegroups.com.

Nelson Radford

unread,
Nov 18, 2025, 7:49:13 AMNov 18
to valt...@valtecom.com.br, Harbour Minigui
I have similar issues from time to time.

Thank you,
Nelson Radford

--

Ivanil Marcelino

unread,
Nov 18, 2025, 5:00:39 PMNov 18
to Harbour Minigui


Ola Valtecom;

Ha um tempo gravei o vídeo abaixo; "aparentemente" você esta com problema de pilha,..justificaria o porquê de ocorrer ocasionalmente..

Designer Minigui - Trabalhando com CHILD (Problemas com Pilhas)

--

José Quintas

unread,
Nov 19, 2025, 12:09:20 PMNov 19
to Harbour Minigui
A pilha não pode ser única.
Em multithread isso fica muito mais em evidência, porque cada thread precisa sua própria pilha.

stack can't be unique.
On multithread this becames more visible, because each thread needs it's own stack.

José M. C. Quintas

Ronaldo Geniais

unread,
Nov 25, 2025, 9:15:00 AMNov 25
to Harbour Minigui
Eu vi o video de Ivanil,
tentei fazer ajustes no meu sistema,
porem  aquela linha do activate,  nao consigo colocar os dois forms,
quando compilo com ide da minigui,  da erro.
Eu nao trabalho com form,  eu converto o form para prg,  isso seria o problema ?

Ivanil Marcelino

unread,
Nov 26, 2025, 5:21:28 PMNov 26
to Harbour Minigui

Hello Ronaldo,

Since you didn’t provide the error details or an example, I will address your question directly:

“…I don’t work with forms; I convert the form to a PRG. Could that be the problem?”

Using the form embedded in the PRG or loading it externally does not affect the functionality. The difference is mainly architectural. Embedding the form inside the PRG is generally less organized from a maintenance perspective, as it mixes the presentation layer with business logic. Keeping them separate makes the PRG cleaner and improves overall code readability.

The preprocessor will merge everything before compilation anyway, so the runtime behavior remains the same. Working with FMG forms, however, gives you more flexibility and allows reuse in several different contexts, for example:

Load window frmpesquisa as formPesquisa_cliente 
Activate window formPesquisa_cliente 

Load window frmpesquisa as formPesquisa_fornecedor 
Activate window formPesquisa_fornecedor 

Load window frmpesquisa as formPesquisa_produto 
Activate window formPesquisa_produto

Although it is possible to encapsulate this into a single function, the structure above keeps the code more readable and easier to maintain. It’s important to consider that other developers may continue working on the project, so establishing clear and consistent standards helps maintain alignment with common industry practices.

Best regards.

Ronaldo Geniais

unread,
Dec 2, 2025, 4:16:18 PM (12 days ago) Dec 2
to Harbour Minigui
Hello Ivanil,
thanks to your excellent explanation and example about the problem with stacking Child windows,
I was able to come up with an alternative to minimize my problem.
From the example you gave, I understood that child windows should be closed in the reverse order of how they were opened,
because when there is more than one active child window, if I close one without checking the order in which they were opened,
a stack error occurs. So I created a function that I run in the window's init, and if the window is a child,
I add it to an array, so all child windows are stacked in the array in the order they were opened.
When trying to close a Child window, I check if it is the last in the array; if it is,
I allow it to be closed and remove it from the array. If it is not the last in the array,
I send a warning to the user that they must close window xxx before closing the current window.
In the same array, I store the form's title so the user can identify which form should be closed.

This seems to solve the problem.
Here is the program I made,
remembering that you need to add the functions in the INIT and Close of the Form.

I hope this can help someone who has this problem,
if something I did or said is not coherent, I would appreciate it if you could guide me.  



Ola Ivanil
gracas a sua otima explicacao e exemplo sobre o problema com empilhamento com janelas Child,
eu consegui fazer uma alternativa para minimizar o meu problema.
Pelo exemplo que voce deu, eu entendi que as janelas child devem ser fechadas na ordem inversa
a que sao abertas,  pois quando ha mais de uma janela child ativa,  se eu fechar sem verificar a ordem
de abertura,  ocorre o erro de pilha.
Assim eu fiz uma funcao que executo no init da janela, e se a janelar for child, eu adiciono ela em um
array,  e assim todas as janelas child ficam empilhadas no array na ordem em que foram abertas.
Ao tentar fechar uma janela Child, eu verifico se ela é a ultima do Array,  se for,  eu permito que
ela seja fechada e removo ela do array,  caso ela nao seja a ultima do array, eu envio um aviso
ao usuario de que tem que fechar a janela xxx  antes de fechar a janela atual.
no mesmo array, eu guardo o Title do formulario para que o usuario identifique qual formulario
deve ser fechado.
Isso parece resolver o problema.
Segue o prg que fiz,
lembrando que tem que adicionar as funcoes  no INIT e no Close do Formulario.

Espero que isso possa contribuir para alguem que tenha esse problema,
se algo que fiz ou falei nao estiver coerente, agradeco se puderem me orientar.
WinControle.prg

Ivanil Marcelino

unread,
Dec 2, 2025, 7:27:54 PM (12 days ago) Dec 2
to Ronaldo Geniais, Harbour Minigui

🇧🇷 

Olá, Ronaldo!

Fico muito feliz em saber que minha explicação ajudou de alguma forma. Uma das coisas que mais gosto na programação é justamente essa liberdade: quase sempre há diversas maneiras de resolver um problema. Alguns podem concordar, outros não, mas para mim o mais importante é alcançar o resultado desejado — se funciona e atende à necessidade, então já é um bom caminho.

Seria interessante, se possível, você disponibilizar um exemplo compilável. Isso facilita bastante a troca de ideias, pois cada um pode ter pequenas diferenças na forma de programar, e tendo um código compilável conseguimos analisar exatamente o mesmo cenário. Isso também seria muito útil para a comunidade, já que aparentemente outras pessoas enfrentam esse mesmo problema.

Inclusive, na pasta do Git, em samples/pilha, há um exemplo que trabalha com várias janelas child simultâneas, independentemente da ordem de fechamento e sem necessidade de códigos extras nos eventos de fechamento.

Se você conseguir isolar apenas a parte essencial do seu sistema, criando um pequeno cenário compilável, seria ótimo — mas é apenas uma sugestão. No fim, se você e seu cliente estão satisfeitos com a solução implementada, isso é o que realmente importa.

Grande abraço,
Ivanil


🇺🇸 

Hello Ronaldo,

I’m very glad to hear that my explanation was helpful in some way. One of the things I enjoy most about programming is this freedom: there are almost always several ways to solve a problem. Some people may agree, others may not, but for me the most important thing is achieving the desired result — if it works and meets the requirement, then it’s already a good path.

If possible, it would be great if you could provide a compilable example. This makes idea-sharing much easier, since everyone may have slight differences in their coding style, and having something that can be compiled allows us to analyze exactly the same scenario. It would also be very helpful to the community, as it seems other people are experiencing this same issue.

By the way, in the Git folder under samples/pilha, there is an example that handles multiple child windows simultaneously, regardless of the closing order and without requiring extra code in the close events.

If you can isolate just the essential part of your system and create a small compilable scenario, that would be great — but it’s only a suggestion. In the end, if you and your client are satisfied with the solution you implemented, that’s what truly matters.

Best regards,
Ivanil


Reply all
Reply to author
Forward
0 new messages