Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DO FORM resets table pointer?
Message
From
02/10/1999 15:33:23
 
 
To
01/10/1999 20:40:07
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00271829
Message ID:
00272001
Views:
28
>>>I have a form which opens a table, sets the table pointer to an arbitrary value, then calls another form.
>>>
>>>If I break at the first line of the Load of the called form, a quick check shows that the table pointer has been returned to the top of the table.
>
>>I believe the DE is called prior to the load. Do you have any code in the DE that might reposition the record?
>
>No. But actually, I thought the Load executes prior to the DE.

The De's OpenTables and then the De's BeforeOpenTables and then the load fires.

Here's some code to populate all the methods and events of a test form.
Make sure that you don't have a pre-existing test.dbf or test screen. You can bypass the parameters piece, which takes a while. But some of the form methods require the parameters to be in place prior to any method code being run.
#DEFINE knForm			1
#DEFINE knDe			2
#DEFINE	knType			3
#DEFINE knInclMethods	1
#DEFINE kcEol			CHR(10)

LOCAL lnParms, llWriteOk, loForm, loDe, lcMethodCode
LOCAL ARRAY laForm[1], laDe[1]

* DCC - Start fresh
CLOSE ALL
ERASE Test.SCX
ERASE Test.SCT
ERASE Test.DBF

* DCC - Build the list of methods
CREATE FORM Test NOWAIT

=ASELOBJ( laForm, knForm )

loForm = laForm[1]

IF TYPE("loForm.Name" ) # "C"
	=MESSAGEBOX( "Could not get form reference." )
	RETURN .F.
ENDIF

lnTotMembers = AMEMBERS( laMembers, loForm, knInclMethods )

* DCC - Add parameters for the form
FOR lnCurMember = 1 TO lnTotMembers

	lcCurMember = laMembers( lnCurMember, 1 )
	lcType = PEMSTATUS( loForm, lcCurMember, knType )
 	IF INLIST( lcType, "Method", "Event" )
	 	KEYBOARD "*" + CHR(23) + CHR(23)
		MODIFY FORM Test METHOD &lcCurMember NOWAIT
 	ENDIF

	CLOSE ALL

 	MODIFY FORM Test NOWAIT
	
	=ASELOBJ( laForm, knForm )
	loForm = laForm[1]
	
ENDFOR

* DCC - Now write out the parameters to the DE

=ASELOBJ( laDe, knDe )

loDe = laDe[1]

IF TYPE( "loDe.Name" ) # "C"
	= MESSAGEBOX( "Could not get a DE reference." )
	RETURN .F.
ENDIF

* DCC - Add one table
CREATE TABLE Test ( cName C(20) )

loDe.AddObject( "Test", "Cursor" )
loDe.Test.CursorSource =  "Test.dbf" 

* DCC - Now add parameters for the DE

* DCC - Be sure to save the form with the cursor here.
KEYBOARD CHR(23)
DOEVENTS

MODIFY FORM Test NOWAIT

* DCC - Now add method code to display the program()
lcMethodCode = "WAIT WINDOW PROGRAM()"

=ASELOBJ( laForm, knForm )

IF TYPE( "laForm[1]" ) # "O"
	=MESSAGEBOX( "Could not get form reference." )
	RETURN .F.
ENDIF

llWriteOk = .T.

loForm = laForm[1]

llWriteOk = fWriteAll( loForm, lcMethodCode )
IF llWriteOk

	=ASELOBJ( laDe, knDe )
	
	IF TYPE( "laDe[1]" ) # "O"
		=MESSAGEBOX( "Could not get a DE reference." )
		RETURN .F.
	ENDIF
	
	loDe = laDe[1]
	=fWriteAll( loDe, lcMethodCode )
	
	=fWriteAll( loDe.Test, lcMethodCode )
	
	KEYBOARD CHR(23)
	DOEVENTS
	
	DO FORM Test
	
ENDIF

* EOP -- Main



FUNCTION fWriteAll
LPARAMETERS	toObject, tcMethodCode
LOCAL lnParms, llWriteOk, lnTotMembers, lcCurMember, lnCurMember, lcNewMethodCode, lcOldMethodCode
LOCAL ARRAY laMembers[1]

lnParms = PCOUNT()
DO CASE
	CASE lnParms < 2
		=MESSAGEBOX( "You must send an Object and a Method Code in " + PROGRAM() + "." )
		RETURN .F.

	CASE TYPE( "toObject" ) # "O" OR ISNULL( toObject )
		=MESSAGEBOX( "A object Object must be sent in " + PROGRAM() + "." )
		RETURN .F.
		
	CASE TYPE( "tcMethodCode" ) # "C" OR EMPTY( tcMethodCode )
		=MESSAGEBOX( "A character Method Code must be sent in " + PROGRAM() + "." )
		RETURN .F.		

ENDCASE

llWriteOk = .T.
lnTotMembers  = AMEMBERS( laMembers, toObject, knInclMethods )

FOR lnCurMember = 1 TO lnTotMembers

	lcCurMember = laMembers( lnCurMember, 1 )
	lcType = PEMSTATUS( toObject, lcCurMember, knType )
	IF INLIST( lcType , "Method", "Event" )
		ON ERROR llWriteOk = .F.
		lcOldMethodCode = toObject.ReadMethod( lcCurMember )
		
		lcNewMethodCode = lcOldMethodCode + kcEol + tcMethodCode
		
		toObject.WriteMethod( lcCurMember, lcNewMethodCode )
		IF NOT llWriteOk
			ON ERROR
			=MESSAGEBOX( "Error writing " + lcType + "."  )
			EXIT
		ENDIF
		ON ERROR
	ENDIF
	
ENDFOR	

RETURN llWriteOk

* EOF - fWriteAll
HTH
Previous
Reply
Map
View

Click here to load this message in the networking platform