recursive call causing stack overflow.

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

franco
Posts: 816
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

recursive call causing stack overflow.

Post by franco »

I thought I would start a new topic because the hmg 3.4.4 topic was so long and many thoughts.
I still have the same problem that Mario had on loosing captions and eventually crashing program after heavy program usage.
I found in Marios and my code the following and wonder if it is causing the problem.
Mario
load window form121
form121.text.121.setfocus <------------------------- window is not active to set focus to
activate window form121

My code
Define window w1
define textbox t1
Define button b1 .......... //FOUND SOMETHING ELSE IN MY PROGRAM Added to post
action {|{ b?()}, W1.B1.Setfocus}} ......... //Added to post
on gotfocus w1.b1.setfocus ........ // Added to post DO NOT KNOW WHY I HAVE THIS COULD BE PROBLEM ??
endbutton .........................................//
end window
w1.t1.setfocus <------------------------- window is not active to set focus to
if something
endif
activate window w1
Is there something wrong here. I have not tried because it is thoughout my program and it takes a long day of use to crash.
Any thoughts.
Thanks .... Franco
All The Best,
Franco
Canada
User avatar
luisvasquezcl
Posts: 1258
Joined: Thu Jul 31, 2008 3:23 am
Location: Chile
Contact:

Re: recursive call causing stack overflow.

Post by luisvasquezcl »

In this line

Define button b1 .......... //FOUND SOMETHING ELSE IN MY PROGRAM Added to post
action {|{ b?()}, W1.B1.Setfocus}} ......... //Added to post
on gotfocus w1.b1.setfocus

you are calling the setfocus event every time the control gets the focus recursively. that's why the fault occurs.
franco
Posts: 816
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: recursive call causing stack overflow.

Post by franco »

Luis thanks for response
What do you think. Is it ok to setup things between end window and activate window like.
Define window w1
define textbox t1
Define button b1
end window
/////////////////////////IS ALL OF THIS OK BETWEEN END WINDOW AND ACTIVE WINDOW /////////////////////////
w1.t1.setfocus
if variable
w1.b1.visible := .f.
endif
////////////////////////////////////////////////////////////////////////////
activate window w1

Franco
All The Best,
Franco
Canada
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: recursive call causing stack overflow.

Post by mol »

It's OK in my opinion.
I' love to use IDE to define forms, but often I use such a code

Code: Select all

load window form1

// do sth. with controls, eg. set initial values, hide/show/enable controls
// when everything is set

activate window form1
franco
Posts: 816
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: recursive call causing stack overflow.

Post by franco »

I use this a lot. But since my problem with stack overflow I wasn`t sure where it was coming from, but hopefully it is my onfocus..setfocus.
I use ide but the modules side.
Thanks Mol
Franco
All The Best,
Franco
Canada
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: recursive call causing stack overflow.

Post by mol »

Maybe try to stop events tiil window activation:

Code: Select all

StopControlEventProcedure ( cControlName, cFormName, lStop )
franco
Posts: 816
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: recursive call causing stack overflow.

Post by franco »

Is the following allowed
parameters something
define window w1
...
...
end window
w1.... setfocus
w1.activate
if something THIS IS WHAT I WONDER AFTER ACTIVATE BEFORE RETURN
something CAN THIS BE HERE OR DOES IT [ HAVE] TO BE IN A PROCEDURE OR FUNCTION
endif
return something
Franco
All The Best,
Franco
Canada
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: recursive call causing stack overflow.

Post by andyglezl »

Sobre el comentario de Mol, aquí está un ejemplo, para ver si les sirve.
*--------------------------------------------------------
About Mol's comment, here is an example, to see if it serves you.

valida.png
valida.png (8.63 KiB) Viewed 3192 times

Code: Select all

/*	Ejemplo para validar texboxs no vacios   	-----   		AndyGlezL		*/
/*	Example to validate non-empty texboxs 		----- 			AndyGlezL	 	*/
#include "hmg.ch"

FUNCTION Main()

	DEFINE WINDOW Form_Main AT 0,0 WIDTH 640 HEIGHT 600 TITLE 'ON LOSTFOCUS TEST  ´By AndyGlezL' MAIN
		
		SET NAVIGATION EXTENDED			// Para que al oprimir ENTER tambien valide		// so that when pressing ENTER also validate
		ON KEY ESCAPE OF Form_main ACTION Form_main.Release

		@  10 ,  10 LABEL L_Warning 	WIDTH 250 HEIGHT 20  VALUE '' SIZE 12 FONTCOLOR WHITE BACKCOLOR RED BOLD CENTERALIGN
					Form_main.L_Warning.Hide

		nReng := 60
		nCpos := 10
		FOR i1 = 1 TO nCpos
			nColu1 := 10
			nColu2 := 90
			nReng += 25
			cLBOpc := "LBL_"+STRZERO( i1, 2 )
			cTBOpc := "TXB_"+STRZERO( i1, 2 )
			@ nReng , nColu1 LABEL 	&cLBOpc.  OF Form_Main VALUE 'TEXT'+STRZERO( i1, 2 ) WIDTH 80  HEIGHT 20 
			@ nReng , nColu2 TEXTBOX &cTBOpc. OF Form_Main VALUE ''					     WIDTH 150 HEIGHT 20 ON LOSTFOCUS CkCtrolValue( ThisWindow.Name, This.Name )
		NEXT

	END WINDOW
	CENTER WINDOW Form_Main
	ACTIVATE WINDOW Form_Main
RETURN
*------------------------------------------------------------------------------------------------------
FUNCTION CkCtrolValue( cWind, cCtrol )
	IF EMPTY( GetProperty( cWind, cCtrol, 'Value' ) )
		DoMethod( cWind, cCtrol, 'SetFocus' )
		SetProperty( cWind, 'L_Warning', 'Value', 'FIELD ' + CCTROL + ' CAN NOT BE EMPTY!'  )
		Form_main.L_Warning.Show
		StopControlEventProcedure( cCtrol, cWind, .f. )		// No permite Salir del TEXTBOX		// Does not allow Exit from TEXTBOX
	ELSE
		Form_main.L_Warning.Hide
	ENDIF
RETURN( .t. )
*------------------------------------------------------------------------------------------------------
Andrés González López
Desde Guadalajara, Jalisco. México.
franco
Posts: 816
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: recursive call causing stack overflow.

Post by franco »

Thanks Mol, and Andy
This could be used in my editbox called mybox in my program where clients fingers are still to fast for window speed because they are used to
dos-clipper.
But I am still working on my caption loss and crash (stack overflow ?). I am finding things I am not sure of in my code.
1.. Can I add code between END WINDOW and ACTIVATE WINDOW as sample above.
2.. which is correct after DBCREATETEMP("AR1",CF)
CLOSE AR1
RELEASE AR1
DBDROP("AR1")
or,
CLOSE AR1
DBDROP("AR1")
Franco
All The Best,
Franco
Canada
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: recursive call causing stack overflow.

Post by andyglezl »

franco wrote: Fri Nov 09, 2018 5:33 pm But I am still working on my caption loss and crash (stack overflow ?). I am finding things I am not sure of in my code.
1.. Can I add code between END WINDOW and ACTIVATE WINDOW as sample above.

Yo no lo hago de esta forma, si tengo que inicializar algo, lo hago antes de MAIN ó ON INIT HagoAlgo() del MAIN
Tendras un ejemplo funcional de como lo quieres hacer ?
+-------------------------------------------------------------------------------------------------------------------------------------------
I do not do it this way, if I have to initialize something, I do it before MAIN or ON INIT HagoAlgo() of MAIN
Will you have a functional example of how you want to do it?

2.. which is correct after DBCREATETEMP("AR1",CF)

Asumo que al ser "temporal" , el archivo se borrará solo al darle CLOSE.
DBDROP("AR1") es para cuando lo creas em memoria.
*--------------------------------------------------------------------------------------------------
I assume that being "temporary", the file will be deleted only by giving CLOSE.
DBDROP("AR1") is for when you create it in memory.


CLOSE AR1
RELEASE AR1
DBDROP("AR1")
or,
CLOSE AR1
DBDROP("AR1")
Franco
Andrés González López
Desde Guadalajara, Jalisco. México.
Post Reply