FUNCTION CanDelete() local lcHasChildRecords lcHasChildRecords = HasChildRecords() if not empty(lcHasChildRecords) * Can't delete. Records in table ... ErrorMsg("No se puede borrar. Hay datos en " + lcHasChildRecords + ".") return .F. endif ENDFUNC FUNCTION HasChildRecords() if CursorGetProp("SourceType") # 3 && not a table return "" endif *!* lParameters tlShowErrors *!* if parameters() < 1 *!* tlShowErrors = .T. *!* endif local lnSelect lnSelect = select() if not used("RelationsForDelete") open database database adbobjects(arelations, "relation") create cursor RelationsForDelete (child C(30), parent C(30), childtag C(10), parenttag C(10), ri C(10)) append from array arelations select *; from RelationsForDelete; into cursor RelationsForDelete; where substr(ri, 2, 1) = "R" index on Parent tag Parent endif local lcError, laFields(1), lcTableName, lcChildTable, lcChildAlias, lcParentTag, lcChildTag,; lcSeekExpr, lcParentKey lcError = "" select (lnSelect) afields(laFields) lcTableName = upper(laFields(12)) if empty(lcTableName) && probably a free table return "" endif use (dbf()) again alias "CanDelete_ParentTable" in 0 select RelationsForDelete scan for parent = lcTableName lcParentTag = alltrim(ParentTag) lcChildTag = alltrim(ChildTag) lcChildTable = alltrim(Child) lcChildAlias = "CanDelete_" + lcChildTable select CanDelete_ParentTable set order to (lcParentTag) lcParentKey = key() select (lnSelect) lcSeekExpr = eval(lcParentKey) if used(lcChildAlias) select (lcChildAlias) else select 0 use (lcChildTable) again alias (lcChildAlias) endif set order to (lcChildTag) if seek(lcSeekExpr) lcError = lcChildTable exit endif endscan select (lnSelect) use in CanDelete_ParentTable return lcError ENDFUNC