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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call the customized CA class w/o DE 3

Status
Not open for further replies.

ArthurLiu88

Programmer
Aug 5, 2006
16
CN
I buildup my own CursorAdapter class, I can use them like the following code in DataEnviroment.OpenTables method:
this.AddObject("o", "myCursorAdapter")
It works fine.

But how can I apply it in the myForm class, because classes doesn't support DE. There is same question for toolbar or menu.

Many thanks
Arthur Liu (Shanghai, China)
 
You could add a CA programaticly in form' DE:
Code:
thisform.DateEnvironment.NewObject([MyCAclass],[CAClassLib])

or:
Code:
thisform.AddProperty([MyCursor])
thisform.MyCursor  = NewObject([MyCAclass],[CAClassLib])
The code above is valid for any other class (toolbar, container, etc.)
In menu you could only use variable, becasue menu is not an object.


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Thanks

In myForm.Load method, I write

thisform.AddProperty([MyCursor])
thisform.MyCursor = NewObject([MyCAclass],[CAClassLib])
thisform.MyCursor.CursorFill()

It works.

Many thanks
Arthur Liu (Shanghai, China)
 
Another question, how can I keep the cursor (which is created from CA) opened after the form is released. I set the DE.AutoCloseTables to false, but it does not work.

Thanks

Arthur Liu (Shanghai, China)
 
Hi Arthur,

If the cursor is needed by an entity other than the form, perhaps the form isn't the entity that should be in charge of opening and closing the cursor. Perhaps the CA instance should belong to the entity that needs the data after the form has closed.

pamela
 
Hi Arthur,

how can I keep the cursor (which is created from CA) opened after the form is released

The reason the cursor is closing is probably that the form has a private data session (the DataSession property is set to 2). You could fix that by setting the property to 1, but that has other implications.

If you're not sure of the effects of giving a form a private or default data session, you'll find it worthwhile to read up on it in the help. It's quite an important issue.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks Pamela, But I want to know what kind of entity I can choose to bind with CA instance other than FORM.

Arthur Liu (Shanghai, China)
 
Thanks Mike. But myForm.DataSession is set to 1 (Default Data Session)

I'm worried is there any coding wrong.

In myform.load, I write:
IF USED("myCursor")
REQUERY("myCursor")
ELSE
thisform.DataEnvironment.NewObject("myObject", "myCAClass")
thisform.DataEnvironment.myObject.CursorFill()
ENDIF
And thisform.DataEnvironment.AutoCloseTables is set to .F.

In myCAClass, I only change the code in CursorFill as follows:
LPARAMETERS tlUseCursorSchema, tlNoData, tuOptions, toSource
LOCAL lWasError, lcSQLConnect

TRY
lWasError = .F.
lcSQLConnect = [MyConnectString]

WITH this
.Name = [MyCAName]
.Alias = [MyCursor]
.Tables = [MySQLTable]
.SelectCmd = [SELECT MyFields FROM MySQLTable WHERE MyCondition]
.CursorSchema = […]
.KeyFieldList = [idnbr]
.UpdateNameList = […]
.UpdatableFieldList = […]
.AllowDelete = .T.
.AllowInsert = .T.
.AllowUpdate = .T.
.BatchUpdatecount = 1
.BufferModeOverride = 5
.CompareMemo = .T.
.DataSourceType = [ODBC]
.DataSource = SQLSTRINGCONNECT(lcSQLConnect)
.FetchAsNeeded = .T.
.FetchMemo = .T.
.FetchSize = 100
.MaxRecords = -1
.SendUpdates = .T.
.UpdateType = 1
.UseCursorSchema = .T.
.UseMemoSize = 255
.UseTransactions = .T.
.WhereType = 3
ENDWITH
WAIT CLEAR
CATCH
WAIT CLEAR
lWasError = .T.
ENDTRY

IF lWasError
AERROR(laError)
MESSAGEBOX("CursorAdapter Error" + CR + CR + laError(2), MB_ICONSTOP, SEM_LOC)
RETURN .F.
ELSE
RETURN DODEFAULT(tlUseCursorSchema, tlNoData, tuOptions, toSource)
ENDIF
 
The issue here is that when the Data Environment is destroyed (as part of closing the form), it takes all its cursor adapters with it. What scope do you really want for this CA/cursor?

Tamar
 
Hi Tamar
When the form is released, the DE would be destroyed too. For the native VFP table or cursor, however, if DataEnvironment.AutoCloseTables is set to false, the cursor can keep using.

My purpose is that after downloading the data from server and handled in form A. The clients can do something else in form B. I don't want download it again in order to decrease the network pressure.

Thanks
Arthur Liu (Shanghai, China)
 
Hi Arthur,

there are two scenarios a cursor of a CA is closed:
a) the datasession, in which the cursor is open is closed
b) the cursoradapter object is destroyed.

Although you have Autoclosetables set to false, the cursoradaptor object (thisform.DataEnvironment.myObject) is destroyed together with the Dataenvironment, as that is destroyed together with Form A.

Solution is to create the CA object outside of the form. It doesn't really matter much where you attach it. It just needs to live longer than the form, so it must be attached somewhere outside. Maybe to _screen or to some other global object you have, maybe have a collection of CAs attached to the _screen.

You need to be aware that a DE is not a Datasession and CA cursor is dependant on the CA object, so you're having three different types of things here. And although the CA cursor itself is no subobject of the CA, and although it is living in the active datasession and therfore also no subobject of the DE, destroying the CA will make the CA tidy up and close it's cursor.

Bye, Olaf.
 
Hi Arthur,

If both form A and form B need access to the data, then the CursorAdaptor should not belong to either one. What you use to hold the object reference to the CursorAdaptor is an additional design issue. As Olaf said, it could be any object with a more global scope.

pamela
 
Finally, I choose myToolbar as the object to hold the cursor.

Many thanks for all of you.
Arthur Liu(Shanghai, China)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top