FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Help : Unable to pass private var to Window's Valid clause
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Help : Unable to pass private var to Window's Valid clause
Posted: Tue Sep 09, 2008 08:36 AM
Friends,

I am getting a variable does not exist error when I try to call a function containing a private array as parameter to the fuction.

A small description about the function

Function Opens a DBF file named ACMASTER.DBF in Shared Mode in a New Work Area with the ALIAS name "AcMaster_ACM".

A MDICHILD window is opend

A xbrowse is used to display the contents of the DBF

when I close the window. It should close the DBF ACMASTER. This is just a beginiing, I will be opening more DBF files in future with different ALIAS names. Because of this reason I add all opened DBF file's ALIAS name into an array mOpenDbfArr:={} thru the functon NetUse(). And when the user close the window I use the VALID clause to call the fuction CloseOpenDBFs(mOpenDbfArr)

But When I call CloseOpenDBFs(mOpenDbfArr) I am getting a variable does not exist error mOpenDbfArr.

mOpenDbfArr is a private variable declared in the beginning of the Fuction AcMAster(). If I change this variable from private to Public then it is working fine.


My Code

*-----------------------------------------*
Function AcMaster()
*-----------------------------------------*
Local oWnd,oBrw
Private mOpenDbfArr:={}

if !Netuse(MastPath+"ACMASTER",SHARED_OPEN,SYS_WRK_AREA,05,"AcMaster_ACM",mOpenDbfArr)
	CloseOpenDBFs(mOpenDbfArr)
	Return NIL
Endif
set inde to &(Mastpath+"ACMASTER"),&(Mastpath+"ACNAME")


DEFINE WINDOW oWnd MDICHILD;
      TITLE "Account Heads" 

oWnd:nHeight:=Round(WndMain():nHeight*.80,0)  // 80% of Main Windows Ht
oWnd:nWidth:=WndMain():nWidth-10              // 1023 -2 == 1021

 @  0, 0 XBROWSE oBrw CELL;
      COLUMNS 'ACCODE','NAME','GRCODE' ;
      SIZE 370,oWnd:nHeight-35 PIXEL ;
      OF oWnd ;
      ALIAS 'AcMaster_ACM' 

oBrw:CreateFromCode() 

ACTIVATE WINDOW oWnd ;
	on INIT oBrw:SetFocus(); 
	VALID CloseOpenDBFs(mOpenDbfArr)  // I am getting error here

*-----------------------------------------------*
Function CloseOpenDBFs(mOpenDbfArr)
*-----------------------------------------------*
Loca mCurWrkArea,i,mAlias
mCurWrkArea:=Select()
for i:=1 to len(mOpenDbfArr)
	mAlias:=mOpenDbfArr[i]
	if Select(mAlias) > 0
		Select &mAlias
		use
	Endi
Next
if mCurWrkArea > 0
	Sele &mCurWrkArea
Endi
MsgInfo("Executed Close DBF")
Return .T.


My idea is to Close the DBF files opend in this Function AcMaster() when the user quit that function by closing the Window oWnd.

Could you please point out where I have went wrong.

Regards

Anser
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Help : Unable to pass private var to Window's Valid clause
Posted: Tue Sep 09, 2008 10:39 AM
This is in continuation with my above posted problem



I get error when I close the window containing the xBrowse. (IT tries to run the function VALID CloseOpenDBFs(mOpenDbfArr) ). Error message says that the Private variable mOpenDbfArr does not exist

After the error message is shown then an Application error (Screen snapshot pasted above) occurs.

Right now my Window is MDICHILD

Code

DEFINE WINDOW oWnd MDICHILD;
      TITLE "Account Heads"


But if I remove the MDICHILD clause, then I am NOT GETTING the above said Application error

DEFINE WINDOW oWnd ;
      TITLE "Account Heads"


Any help ?

Regards

Anser
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Help : Unable to pass private var to Window's Valid clause
Posted: Tue Sep 09, 2008 03:07 PM

Anser,

My suggestion is to never use privates--they are very prone to generating hard to find errors.

I also suggest making your variable a file-wide static.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Help : Unable to pass private var to Window's Valid clause
Posted: Tue Sep 09, 2008 09:00 PM

Anser,

You are declaring the private variable in the function where the MDICHILD window is defined and activated, but the execution of the MDICHILD window is non modal, so your application returns from that function and the private memvar is destroyed!

Function AcMaster()
...
Private mOpenDbfArr:={}

DEFINE WINDOW ... MDICHILD

ACTIVATE WINDOW ... // the execution does not stops here!

return nil // when you exit from here the private memvar is destroyed!

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Help : Unable to pass private var to Window's Valid clause
Posted: Wed Sep 10, 2008 05:39 AM
Antonio Linares wrote:Anser,

You are declaring the private variable in the function where the MDICHILD window is defined and activated, but the execution of the MDICHILD window is non modal, so your application returns from that function and the private memvar is destroyed!

Function AcMaster()
...
Private mOpenDbfArr:={}

DEFINE WINDOW ... MDICHILD

ACTIVATE WINDOW ... // the execution does not stops here!

return nil // when you exit from here the private memvar is destroyed!


Dear Antonio,

That was a very new information to me. I would like to know more about the execution flow while using different windows/MDI/MDICHILD/DIALOG. From where can I get more info on this ?

Regards

Anser
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Help : Unable to pass private var to Window's Valid clause
Posted: Wed Sep 10, 2008 06:11 AM

Anser,

Please review this section in the FiveTech wiki (in development):

http://wiki.fivetechsoft.com/doku.php?i ... ming_guide

Look for "Additional notes for Modal and Non Modal execution"

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion