local laDE[1], ; lnDE, ; loDE, ; loObject lnDE = aselobj(laDE, 2) if lnDE > 0 loDE = laDE[1] for each loObject in loDE.Objects if upper(loObject.BaseClass) == 'CURSOR' ConvertCursorToCA(loObject) endif upper(loObject.BaseClass) == 'CURSOR' next loDE endif lnDE > 0 return function ConvertCursorToCA(toCursor) local lcTempName, ; loCursor, ; lcDBC, ; llOpenedDBC, ; llOpenedCursor, ; lcAlias, ; lcSchema, ; lcUpdateNames, ; lcUpdatable, ; laTags[1], ; lnTags, ; lnTag, ; lcKeyFields, ; lcKeyExpr, ; laFields[1], ; lnFields, ; lnI, ; lcField, ; lcType, ; lcLen, ; lcDec, ; lcCode, ; lcCursor, ; lcName * Create the CursorAdapter object. lcTempName = sys(2015) toCursor.Parent.AddObject(lcTempName, 'CursorAdapter') loCursor = evaluate('toCursor.Parent.' + lcTempName) * Open the database if necessary. lcDBC = toCursor.Database llOpenedDBC = .F. do case case empty(lcDBC) case dbused(lcDBC) set database to (lcDBC) otherwise open database (lcDBC) llOpenedDBC = .T. endcase * Open the cursor if necessary. llOpenedCursor = .F. lcAlias = upper(juststem(toCursor.CursorSource)) if not used(lcAlias) use (toCursor.CursorSource) again shared noupdate nodata in 0 ; alias (lcAlias) llOpenedCursor = .T. endif not used(lcAlias) * Set the SelectCmd and auto-updating properties. loCursor.SelectCmd = 'select * from ' + ; iif(empty(lcDBC), toCursor.CursorSource, lcAlias) + ; iif(empty(toCursor.Filter), '', ' where ' + toCursor.Filter) lcSchema = '' lcUpdateNames = '' lcUpdatable = '' lnTags = ataginfo(laTags, '', lcAlias) lnTag = iif(lnTags = 0, 0, ascan(laTags, 'Primary', -1, -1, 2, 9)) lcKeyFields = '' if lnTag > 0 lcKeyExpr = laTags[lnTag, 3] else lcKeyExpr = '' endif lnTag > 0 lnFields = afields(laFields, lcAlias) for lnI = 1 to lnFields lcField = laFields[lnI, 1] lcType = laFields[lnI, 2] lcLen = transform(laFields[lnI, 3]) lcDec = transform(laFields[lnI, 4]) lcUpdateNames = lcUpdateNames + iif(empty(lcUpdateNames), '', ',') + ; lcField + ' ' + lcAlias + '.' + lcField lcUpdatable = lcUpdatable + iif(empty(lcUpdatable), '', ',') + lcField lcSchema = lcSchema + iif(empty(lcSchema), '', ',') + lcField do case case lcType = 'C' lcSchema = lcSchema + ' C(' + lcLen + ')' case lcType $ 'NF' lcSchema = lcSchema + ' ' + lcType + '(' + lcLen + ',' + lcDec + ; ')' case lcType = 'B' lcSchema = lcSchema + ' ' + lcType + '(' + lcDec + ')' otherwise lcSchema = lcSchema + ' ' + lcType endcase if atc(lcField, lcKeyExpr) > 0 lcKeyFields = lcKeyFields + iif(empty(lcKeyFields), '', ',') + lcField endif atc(lcField, lcKeyExpr) > 0 next lnI loCursor.CursorSchema = lcSchema loCursor.Tables = lcAlias loCursor.UpdateNameList = lcUpdateNames loCursor.UpdatableFieldList = lcUpdatable loCursor.KeyFieldList = lcKeyFields * Set other properties of the CursorAdapter. *loCursor.BufferModeOverride *NoDataOnLoad *Order *ReadOnly if not empty(toCursor.Tag) loCursor.Tag = toCursor.Tag endif not empty(toCursor.Tag) if not empty(toCursor.Comment) loCursor.Comment = toCursor.Comment endif not empty(toCursor.Comment) * Write any code to the appropriate events. lcCode = toCursor.ReadMethod('Init') if not empty(lcCode) loCursor.WriteMethod('Init', lcCode) endif not empty(lcCode) lcCode = toCursor.ReadMethod('Destroy') if not empty(lcCode) loCursor.WriteMethod('Destroy', lcCode) endif not empty(lcCode) lcCode = toCursor.ReadMethod('Error') if not empty(lcCode) loCursor.WriteMethod('Error', lcCode) endif not empty(lcCode) * Remove the Cursor object and set the Name and Alias of the CursorAdapter. lcCursor = toCursor.Alias lcName = toCursor.Name loCursor.Parent.RemoveObject(toCursor.Name) loCursor.Alias = lcCursor loCursor.Name = lcName * Clean up and exit. if llOpenedCursor use in (lcAlias) endif llOpenedCursor if llOpenedDBC close databases endif llOpenedDBC returnDoug