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

Help with Set DELETED ON 1

Status
Not open for further replies.

Judi201

Technical User
Jul 2, 2005
315
0
0
US
Hi,

I am having a problem with deleting records. Tables in a database are opened in the DE and accessed on multiple pages of a pageframe. I SET DELETED ON in the startup program and the record is still visible. I tried putting this in other places to no avail. So obviously I don't understand what is going on. It seems to work until the program is closed and reopened. Then the record is there again. Browsing in the command window does not show it marked for deletion. Will someone please explain what I need to do to make this record not show up. I realize that I must pack to actually remove it but 'in olden days' I could SET DELETED ON and the record was not visible and reading other posts here state the same thing. So does it have something to do with the Data Environment and I am just missing the boat?

Thanks for any help.

Judi
 
Try put SET DELETED ON in form.load
Perhaps where is SET DELETED OFF befor form.load
You need check that with ?SET("DELETED")
ThuVan
 
Judi,
SET DELETE has scope to current DATASESSION only
So if you have a Private Datasession in this form SET DELETED has no effect if you put it in the Main program.
In all forms that have private datasession you must put SET DELETED ON in Form's Load Event.
I create a custom class with ALL SET commands that depends on DataSession wich in Init Event SET's the appropriate settings and in Destroy Event turns them back again.

Borislav Borissov
 

Hi Judi,

Borislav has given you the right answer.

There are about 30 SET commands that apply to the current data session. SET DELETED is one of them. If your form has a private data session (that is, if its DataSession property is set to 2), then the form won't know about any of those SET commands that you issue from outside the form.

The solution is to issue any SET commands needed by a form from the Load of the form. If all your forms inherit from a base form class, then issue the SETs from the Load of that class.

To find a full list of the commands in question, see the Help topic on SET DATASESSION.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Hi Judi.

Here is a class you can use to set the environment. Just add it to your base form class in its Load() method like this:

Code:
Thisform.NewObject( [oEnv], [stdEnv], [stdCustom.vcx] )

Class Definition is:

Code:
**************************************************
*-- Class:        stdenv (f:\wwnew\libs\stdcustom.vcx)
*-- ParentClass:  cusbase (f:\wwnew\libs\basectrl.vcx)
*-- BaseClass:    custom
*-- Time Stamp:   08/01/04 05:03:00 PM
*-- e\class to set and reset environmental settings
*
DEFINE CLASS stdenv AS cusbase
  csysformats = ""
  cansi = ""
  ccentury = ""
  cconfirm = ""
  cdeleted = ""
  cexact = ""
  cexclusive = ""
  nfdow = 0
  cfullpath = ""
  nmemowidth = 0
  cnotify = ""
  cnull = ""
  csafety = ""
  nreprocess = 0
  cstatus = ""
  cstatusbar = ""
  nstrictdate = 0
  ctalk = ""
  cescape = ""
  cdate = ""
  cseparator = ""
  cpoint = ""
  ctextmerge = ""
  Name = "stdenv"

  *-- Sets up the form environment
  PROCEDURE set
    LOCAL loINIMgr, lcDate, lcSeparator
    SET TALK OFF
    *** Set the environment
    *** If we running an executable, there is no need to save settings
    IF VERSION( 2 ) # 0
      SET ESCAPE ON
      SET ASSERTS ON
      This.SaveSettings()
    ELSE
      SET ESCAPE OFF
      SET ASSERTS OFF
      SET STATUS BAR OFF
    ENDIF
    SET SYSFORMATS OFF
    SET DECIMALS TO 4  
    SET CENTURY ON ROLLOVER 60
    SET ANSI OFF
    SET CONFIRM ON
    SET DELETED ON
    SET EXACT OFF
    SET EXCLUSIVE OFF
    SET MULTILOCKS ON
    SET FDOW TO 2
    SET FULLPATH ON
    SET MEMOWIDTH TO 50
    SET NOTIFY OFF
    SET NULL OFF
    SET NULLDISPLAY TO ' '
    SET REPROCESS TO 10 SECONDS
    SET SAFETY OFF
    SET STATUS OFF
    SET STRICTDATE TO 0
    SET TEXTMERGE ON
  ENDPROC

  *-- Resets the environment the way it was
  PROCEDURE reset
    *** Restore the original environment
    *** Can't just use the vfp default settings because these are developers
    *** who may get upset if you change their customized settings
    LOCAL lcSetting
    WITH THIS
      lcSetting = .cCentury
      SET CENTURY &lcSetting
      lcSetting = .cSysFormats
      SET SYSFORMATS &lcSetting
      lcSetting = .cAnsi
      SET ANSI &lcSetting
      lcSetting = .cConfirm
      SET CONFIRM &lcSetting 
      lcSetting = .cDeleted
      SET DELETED &lcSetting 
      lcSetting = .cExact
      SET EXACT &lcSetting 
      lcSetting = .cExclusive
      SET EXCLUSIVE &lcSetting 
      SET FDOW TO .nFdow
      lcSetting = .cFullPath
      SET FULLPATH &lcSetting 
      SET MEMOWIDTH TO .nMemoWidth
      lcSetting = .cNotify
      SET NOTIFY &lcSetting 
      lcSetting = .cNull
      SET NULL &lcSetting 
      SET NULLDISPLAY TO 
      SET REPROCESS TO .nReprocess
      lcSetting = .cSafety
      SET SAFETY &lcSetting 
      lcSetting = .cStatus
      SET STATUS &lcSetting
      lcSetting = .cStatusBar
      SET STATUS BAR  &lcSetting
      SET STRICTDATE TO .nStrictDate
      lcSetting = .cTextMerge
      SET TEXTMERGE &lcSetting
      lcSetting = .cTalk
      SET TALK  &lcSetting
    ENDWITH
  ENDPROC

  PROCEDURE savesettings
    WITH This
      .cCentury	   = SET( 'CENTURY' )
      .cSysFormats = SET( 'SYSFORMATS' )
      .cAnsi       = SET( 'ANSI' )
      .cConfirm    = SET( 'CONFIRM' )
      .cDate	   = SET( 'DATE' )
      .cDeleted    = SET( 'DELETED' )
      .cExact      = SET( 'EXACT' )
      .cExclusive  = SET( 'EXCLUSIVE' )
      .nFdow       = SET( 'FDOW' )
      .cFullPath   = SET( 'FULLPATH' )
      .nMemoWidth  = SET( 'MEMOWIDTH' )
      .cNotify     = SET( 'NOTIFY' )
      .cNull       = SET( 'NULL' )
      .nReprocess  = SET( 'REPROCESS' )
      .cSafety     = SET( 'SAFETY' )
      .cStatus     = SET( 'STATUS' )
      .cStatusBar  = SET( 'STATUS BAR' )
      .nStrictDate = SET( 'STRICTDATE' )
      .cTalk       = SET ( 'TALK' )
      .cEscape     = SET( 'ESCAPE' )
      .cTextMerge  = SET( 'TEXTMERGE' )
    ENDWITH
  ENDPROC

  PROCEDURE Init
    This.Set()
  ENDPROC

  PROCEDURE Destroy
    IF VERSION( 2 ) # 0
      This.Reset()
    ENDIF
  ENDPROC

ENDDEFINE
*
*-- EndDefine: stdenv
**************************************************

Marcia G. Akins
 
Thanks to all of you for the quick responses.

Your answers are what I expected and I have tried setting SET DELETED ON in the form Load and several other places with no luck. I have gone over every place that I have code (at least I think I looked at every place) and I cannot find that DELETED is set to OFF so I do not understand. Can you give me any suggestions for looking for the problem?

Marcia:
I appreciate the code for setting the environment and am embarassed to admit that I don't know how to use it. The classes I have made have all been done visually by getting things like I want and saving as class. I don't know where to put the code to set up the class. Would appreciate any help.

Thuvan1957:
Thanks for the reminder of how to check.


Mike:
I was into the project with the form,pageframe, 3 pages amd the DE working before I started making classes so the form I am using is just the VFP (base?) form. So I'm thinking that I have to start over to create a form with those properties to base things on. I think I have too much invested in this setup to do that so I will put the code in the load of my form. I still want to create such a form to use from now on. Any pointers you can give me will be appreciated greatly.

Thanks again to all

Judi
 
Judi,
Open Trace window in debuger, Open Breakpoint dialog and select "Break when expression is true" in Type In Expression put: SET("DELETED") == "OFF" press Add button and start your form.

Borislav Borissov
 
Thanks Borislav,

I appreciate your help.

Judi
 
Hi Judi.

Marcia:
I appreciate the code for setting the environment and am embarassed to admit that I don't know how to use it. The classes I have made have all been done visually by getting things like I want and saving as class. I don't know where to put the code to set up the class. Would appreciate any help.

You can just copy and paste the code I posted into a prg called SetEnv.prg. Just change this line:


Code:
DEFINE CLASS stdenv AS cusbase

to this:

Code:
DEFINE CLASS stdenv AS custom

Then, in the Load() of your base form class, put this line:

Code:
Thisform.NewObject( [oEnv], [stdEnv], [SetEnv.prg]

Keep in mind that any form instances or subclasses that are based on this form must must have a DODEFAULT() in their Load() method if you have any code in it.



Marcia G. Akins
 
Marcia,
Thanks so much for clearing that up for me. Sometimes it seems like I can make the simplest things hard.

Judi
 
Judi,

SET DELETED OFF is the standard setting for each new datasession, therefore you don#t need to have a SET DELETED OFF in your code.

I'd double check if the records you expect not to see really are deleted. And you may simlpy issue

WAIT WINDOW "DELETED is set "+SET("DELETED") NOWAIT

in the activate event of your form. to see what it is when the form runs. Maybe you just need a refresh of the grid and all is fine.

Bye, Olaf.
 
Olaf,

Thanks for your response. I was just looking to see if maybe somewhere I had set it(DELETED OFF). I did not mean to. I have done as you suggested and the response is SET DELETED is ON. And when I move through the records back and forth, the deleted record is not there. I have checked DELETED in several parts of the program. Always, it is ON. Everything seems fine until I close the program and restart it. Then the record is back. So it cannot be Refresh - right?

Olaf said:
I'd double check if the records you expect not to see really are deleted.

Any tips on how best to do that? Would browsing in the command window show me exactly what the form is seeing? I always thought it would, but maybe not.

I am so confused that I have tried to investigate the possibility that it is, at certain points, accessing another table (same table in a different location - such as a backup) I can find no suggestion that this is true. I really don't have any more ideas.

Will appreciate any suggestions.

Judi
 
Hi Judi,

to check if a record is deleted simply SET DELETED OFF, browse that table and see if you find that record with a record deletion mark, or SET DELETED ON and see if it won't be in the browse window.

Everything seems fine until I close the program and restart it. Then the record is back. So it cannot be Refresh - right?

unprobable, but:
- Do you do RECALL / RECALL ALL somewhere to recover deleted records?
- Is the table by chance compiled into the exe and thereby readonly - unchangable?

Bye, Olaf.
 
Olaf,

No, I have not issued RECALL/RECALL ALL anywhere. I have not compiled into an exe yet, only building application with recompiling. I never include tables in the exe, tho.

Appreciate all suggestions.

Judi
 
Hi Judi,

have you tried THISFROM.Grid1.REFRESH() as a last thing in Init() anyway?

Bye, Olaf.
 
Olaf,
I have tried Refresh() in the Init() of form and saw no difference.

As long as the form is running everything is fine. Close it and come back and the records are there.

I checked to see if buffering made any difference as I am new to that and it does. If I set BUFFERING off (0), then things work as I expected: the records are permanently marked for deletion. My entire EDIT bar depends on buffering so I must see what I am doing wrong there.

This is what I had done.

SET MULTILOCKS ON
Private Data Session on the form.
BufferMode = 2 on the form && It didn't seem that this was needed but I wasn't sure.

On the Properties of the Table, I set BufferModeOverride to 5

This caused my save, cancel and edit to work fine and all data was displayed properly until I hit the delete problem.

Any suggestions appreciated.

Judi
 
Hi Judi,

well, buffered changes finally need to be stored in the table, so you need to issue TABLEUPDATE() or else the changes are reverted. Read the help about the complex functionality that TABLEUPDATE() offers for single row or all rows update and handling errors through update conflicts in mult user environments.

Bye, Olaf.
 
Olaf,

I have read all I can find on buffering and TABLEUPDATE() and finally set all buffering off until I ADD or EDIT. Setting it on then and turning if off with my SAVE or CANCEL has got things working as far as I can tell.

I hope some of you will comment on this strategy so that the thread will not be misleading to anyone who reads this later. I haven't read anywhere that buffering must be off for delete to work.

Thanks for staying with me in this frustrating problem. What problems aren't frustrating?[smile] If we didn't like problems , we shouldn't be trying to program!

Judi
 
Hi Judi,

Buffering definitely does not have to be off for DELETE (or other updates) to work. The table changes just have to be committed (TABLEUPDATE) before closing the table.

Jim
 
Hi Judi,

Setting buffering off should trigger tableupdates, so that is okay, but you won't have much control, when conflicts arise, because two users would edit the same record or one would edit it, while another one deletes it.

Is your application a multi user server/client application at all? If not, you may simply never turn buffering on.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top