Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing cursors as Parameters 2 forms 3

Status
Not open for further replies.

itflash

Programmer
Joined
Jul 18, 2001
Messages
535
Location
GB

Hi all

Is it possible to pass a cursor (CREATE CURSOR) as a parameter to a form? Both forms have private data sessions.


Thanks
ITflash

 
Is it possible to pass a cursor (CREATE CURSOR) as a parameter to a form? Both forms have private data sessions.

Not really directly, you would have to pass it to an array first (or two) as in this example:
Code:
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"
	aarray = .F.
	DIMENSION myarray[1]
	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 144, ;
		Left = 156, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Command1", ;
		Name = "Command1"
	PROCEDURE myfunction
		LPARAMETERS laArray
		**You code here
	ENDPROC
	PROCEDURE command1.Click
		CREATE CURSOR myCursor (name c(20))
		INSERT INTO myCursor (name) VALUES ("Mike")
		INSERT INTO myCursor (name) VALUES ("Paul")
		INSERT INTO myCursor (name) VALUES ("Frank")
		SELECT myCursor
		COUNT TO x
		DIMENSION thisform.myarray[x,1] 
		COPY TO ARRAY thisform.myarray
		local laArray[1]
		= acopy(Thisform.myArray, laArray) 
		thisform.myFunction(@laArray) 
	ENDPROC
ENDDEFINE
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
You could also create an ADO recordset - this is a true object and it could be passed. There are routines to convert RS to Cursors and vice versa. Or you could use the new VFP 8.0 cursor to XML (CURSORTOXML( )) to create a string to pass, and convert it back to a cursor with XMLTOCURSOR( ).

Rick
 
HI

You can use the parameter passing as given below..

Calling Form.. some event..

myFile = SYS(3)
DO myPRG WITH myFile
OR
DO myDefaultEnvironmentForm WITH myFile
** After the return.. you wil have the cursor in (myFile)
SELECT (myFile)
do whatever..

********************

In the called form
** make sure it is Default environment
InitEvent
PARAMETERS tFile
ThisFOrm.cFile = tFile

SOme event where you create the CURSOR..

SELECT .... INTO CURSOR (ThisFOrm.cFile) READWRITE

and release the form as usual..

:-)
ramani :-)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 


Thanks guys....I'll try and use most suitable
[thumbsup2]

ps: I see that cursortoxml is in VFP7. I persume this one would work?

 
Yes, I got carried away - while the Cursor/XML functions were enhanced for VFP 8.0, they were introduced in 7.0 and would work just fine for this situation.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top