Help : Unable to pass private var to Window's Valid clause

Help : Unable to pass private var to Window's Valid clause

Postby anserkk » Tue Sep 09, 2008 8: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

Code: Select all  Expand view
*-----------------------------------------*
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
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby anserkk » Tue Sep 09, 2008 10:39 am

This is in continuation with my above posted problem

Image

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

Code: Select all  Expand view
DEFINE WINDOW oWnd MDICHILD;
      TITLE "Account Heads"


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

Code: Select all  Expand view
DEFINE WINDOW oWnd ;
      TITLE "Account Heads"


Any help ?

Regards

Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby James Bott » Tue Sep 09, 2008 3: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Antonio Linares » Tue Sep 09, 2008 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby anserkk » Wed Sep 10, 2008 5: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
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby Antonio Linares » Wed Sep 10, 2008 6: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 69 guests