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

Intercept "Delete Tag" Warning 1

Status
Not open for further replies.

CDavis

Programmer
May 5, 2000
155
0
0
US
With VFP 9

I am working on a module that allows the end user to delete an index tag.

With SET SAFETY ON, VFP issues a warning when the user attempts to delete a "Primary" or "Candidate" index tag. The warning asks if the user wants to delete it anyway.

I want to prevent the user from deleting a Primary or Candidate index tag so I'd like intercept the attempt before issuing DELETE TAG. Is its possible to test for that condition?

Code:
DO CASE

CASE cTAG = "NO ORDER"  && Do Nothing

OTHERWISE  && Delete Index Tag.

	USE
	USE (myTable) EXCLUSIVE
	DELETE TAG &myTAG
	USE
	USE (myTable)

ENDCASE

Thanks in advance.

-- Chuck
 
And how the user can delete a TAG?
Just do not allow this.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
I agree with Borislav,
Why should the end user delete a tag. Is it because the table was designed bad from the start? If so get their suggestions but still delete it yourself as a developer.

On the other hand you can detect index type using function primary(), candidate() etc as Mike suggested.

Here is one of my routines that I use to create a 'data dictionary' - part collecting index info:
Code:
GetIndexesIntoCursor(_samples+'data','crsIndexes')
Select crsIndexes
Browse

Procedure GetIndexesIntoCursor
  Lparameters tcDataDir,tcCursorName
  tcCursorName = Evl(m.tcCursorName,'crsIndexes')
  Create Cursor (m.tcCursorName) ;
    (TAG_NAME C(10) NoCPTrans, ;
    KEY_EXPR M, ;
    NDXTYPE C(1), ;
    IS_DESC L, ;
    FILTEREXPR M NoCPTrans, ;
    _TABLENAME M NoCPTrans)
  Select 0
  Local Array arrTables[1]
  Local ix,jx
  For ix=1 To Adir(arrTables,Addbs(m.tcDataDir)+'*.dbf')
    Use (Addbs(m.tcDataDir)+arrTables[ix,1])
    If Tagcount()>0
      Local Array arrIndexes[tagcount(),6]
      For jx=1 To Tagcount()
        arrIndexes[m.jx,1] = Tag(m.jx)
        arrIndexes[m.jx,2] = Key(m.jx)
        arrIndexes[m.jx,3] = Icase(;
          Primary(m.jx),'P',;
          Candidate(m.jx),'C',;
          Unique(m.jx),'U','R')
        arrIndexes[m.jx,4] = Descending(m.jx)
        arrIndexes[m.jx,5] = Sys(2021,m.jx)
        arrIndexes[m.jx,6] = arrTables[m.ix,1]
      Endfor
      Insert Into (m.tcCursorName) From Array arrIndexes
    Endif
    Use
  Endfor
Endproc

Cetin Basoz
MS Foxpro MVP, MCP
 
I am wondering what type of users your application has. If it's developers, they should know what they do and if they're foxpro developers you can't really hinder them from deleting tags or do whatever changes to a vfp database.

If you want to allow endusers to sort or seek in user defined tags, then I'd suggest you do give them an additional seperate CDX file and only let them change Tags from within there. They should never even see the initial indexes you need for your basic application logic. And I assume that is not only limited to primary/candidate indexes.

Bye, Olaf.
 
Thanks Mike, I knew that there had to be a function but couldn't find it by searching the help file. I also want to thank everyone else who responded with additional advice.

I guess an explanation is in order. The module I'm updating is part of a suite of Administrative Tools and not available to the average end user. The tool uses 3 arrays and associated list boxes. It displays all the tables in the current data environment, the current list of index tags and a list of fields in the table that are not currently used as an index tag. The program administrator can double-click on fields to add them as index tags and subsequently double-click to delete the tag.

The tool also contains command buttons to change the index order from ascending to descending or to SET ORDER TO no order. Additional buttons are there to browse, open, close, pack, and re-index tables. Its been a great tool for me to have available out in the field when I don't have the development environment available.

The information you guys provided will probably lead to some better enhancements.

Thanks again.

Chuck.
 
"command buttons to change the index order from ascending to descending"

It is far better to just build the variety of needed indicies (Ascending and/or Descending) from the start and then utilize the one that is needed than to actually change the Index expression over and over when needed.

And typically you can change the 'active' index in a variety of ways that does not require some administrator to do so.

You can either utilize a Grid.Column.Header Click or DlbClick Method to toggle through existing indicies as needed. Or you can put a combo box on a form from which to allow the user to 'activate' designated indicies as needed.

These and other methods are much more useful and do not run the risk of compromising the indicies of the data tables.

Good Luck,
JRB-Bldr
 
The module I'm updating is part of a suite of Administrative Tools

Actually, I can see how this might be useful. The point is that the tool is not aimed at end users, or even non-programming administrators. It's more like a builder - something to assist developers with a repetitive task.

I personally wouldn't bother to create an interactive tool for something as easy as adding and deleting indexes. But, in general, I don't see anything terribly wrong with the approach.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top