Re: Pack not working by Willianto
Willianto
Wed Nov 05 14:39:50 CST 2003
Rich:
SWAG: do you have any ON ERROR command? Looks like VFP couldn't open the
file exclusively, and the PACK command failed to run. AFAIK, VFP
should've genereted an error message by then.
By the way, taking a step back, I wonder why you PACK right after you
DELETE a recor? PACK command can be costly if you have large tables. If
you did this because the deleted records keep on showing, maybe you
benefit from my discussion with Igor on this ng:
/start
Hi, Willianto!
You wrote on Sat, 11 Jan 2003 12:55:25 +0700:
> Hi Igor,
>> No!!! It must be in DE.BeforeOpenTables(), as tables and views
>> mentioned
> in
>> form's DE opened prior to form's Load event fired.
> You're right about the DE opened prior to form's load event (I refer
to
> VFP help under 'Tracking Event Sequences' topic). Based on Nancy's and
> your reply, I did a quick test and here is what I found:
> ---------------------------------------------------------
> Location of | Deleted records | Deleted records
> SET DELETED ON | (on view) | (on table)
> ---------------------------------------------------------
> Init Event | SHOWED | SHOWED
> Load Event | SHOWED | NOT SHOWED
> DE.BeforeOpenTables | NOT SHOWED | NOT SHOWED
> ---------------------------------------------------------
> Notes: the view and the table are in the DE.
First of all, SET DELETED ON will work for tables even from
SomeButton.Click
() code, you only have to jerk record pointer (simply GO RECNO() may
help)
and refresh the form - and filter "on deleted" will be in effect (note -
you
can do it for views with REQUERY(), but it will be inefficient to pull
the
data twice).
> Not until now I realized the importance of ability to subclassed the
DE!
> I'm glad VFP8 is on the way. Unfortunately, I cannot use that feature
> now because this project will have to be compiled under VFP7SP1.
You may use one interesting feature (or maybe bug, but it work OK for
me, so
I don't bother on its "legality"). I call it "base class subclassing"
just
run this program, and then try to run any form to see how it works:
PUBLIC oDEHook
m.oDEHook = CREATEOBJECT ("DEHook")
DEFINE CLASS DEHook AS DataEnvironment
Name = "DataEnvironment"
PROCEDURE BeforeOpenTables
SET DELETED ON
MESSAGEBOX ("Now pseudo-base class code is executed")
ENDPROC
ENDDEFINE
Note that the main thing here is line Name = "DataEnvironment"
To remove this pseudo-base class you have to use
m.oDEHook = .F.
CLEAR CLASS DataEnvironment
Also note that if you will have any code in DE.BeforeOpenTables() event
for
some form, you have to include DODEFAULT () function call there to
execute
new "built-in" code.
P.S. I use this technique now (also VFP7SP1) for several purposes, and
one
of them is well-known problem in pathing - fox store path info for any
Cursor objects in DE and so it can use data from some wrong place. With
this
approach you don't need to setup AutoOpen = .F., then change
Cursor.Database
= "\\correct\path\to\database.dbc" or Cursor.CursorSource =
"\\correct\path\to\free\table.dbf" in FORM.Load event and at last call
DE.OpenTables() method...
WBR, Igor
/end
hth,
Willianto