Professional Documents
Culture Documents
Overview
Overview
In this tutorial we will create a set of CA’s that will be used for lookups only. If your fields have a large number
of tables then you need the excellent CABuilder created by Mark McCasland and found
at:http://www.foxite.com/downloads/default.aspx?id=161.
Step 1
From the menu select File/New Class – Create a new class as shown below.
When the class opens in the class designer, Rt. Click it and select “Builder”. Enter a dummy name for the alias.
We will change this later.
Select the data Source. Here we select ODBC to connect to a MSDE data source.
Either use the connection string or an existing DSN. Here we have used a Trusted Connection String. Click
“Test Connection”.
All is well so far and we have connected. Click OK and “OK” in the builder to close it and save the changes.
Step 2
Now we need to make some generic changes to the baseclass. Add the following new properties to the base
class:
cFilterClause – This is where you will add your WHERE clause
cOrderBy – This is the ORDER BY clause of our select
cSelectCmd – This is where the guts of the Select command will go
lNoDataOnLoad – The flag whether we want data to be loaded. Set this to .T.
Close and save the caBaseClass. We will subclass it for our other classes.
Step 3
Create a new class and base it on the caBaseclass created above. This is important so that the new class
inherits our settings.
Click OK to open it in the Class Designer. Rt Click and select Builder. Give the cursor a name.
Click the DataAccess tab and then the Build button so that you can build fields with the correct syntax.
Copy the resultant code as displayed. We may not actually be able to save this because of the 255 chr
restriction in a property. We just do this to build the correct select command. Also this is useful for generating
our schema which can also be copied if required.
Hint: you can also get the correct syntax by using the VFP Query builder on the same source table and then
checking the generated SQL. This is useful for joins etc. Delete the Select and the Generated Cursor Schema
and click OK to save changes. Open the properties and change our custom properties as below.
cClient = ALLTRIM(ThisForm.txtclientno.Value)
WITH ThisForm.grdCrscall
.Recordsource = ""
WITH ThisForm.dataenvironment.cacall
.lNoDataOnLoad = .F. && tell it we WANT data
.cFilterclause = [Call.Clientno LIKE ']+cClient+[%']
.CursorFill()
ENDWITH
.Recordsource = "crscall"
.refresh
ENDWITH
Now run the form, enter an id or part of an id in the text box and click to get the data in the grid. This ends the
tutorial. These CA’s are non updatable and may be used only for lookups. To make them updatable you will
need to set additional properties in the Builder. This is beyond the scope of this tutorial. On the CoDe
magazine site is an excellent article: Introducing the CursorAdapter Class. I have created this tutorial to aid the
development of CursorAdapters after spending many frustrating hours trying to set them up. This is aimed
squarely at the newbie to CursorAdapters.
Bernard Bout is a long time member of the Foxite.COM Community and based in Brisbane, Australia.
Bernard's weblog is here: http://weblogs.foxite.com/bernardbout/
FEEDBACK
I am just trying to start learning CursorAdapters. In Step 1, you start with a class named caBaseClass.
Thereafter, your image shows Class name "cacall". At what point, the name change from caBaseClass to
caCall? (Should I make a new class?) I do not get this. I am using VFP9 and I have no SQL Server installed so
I have to try this on a Native database. Thanks for your guidance.