Board index » delphi » Defeating Automatic Posting

Defeating Automatic Posting

Howdy,
  Has anyone discovered a way to turn off the automatic posting on
record movements?  I'd like to have things set up so that posting occurs
only when the user explicitly asks for it.  At the very least I'd like the
user to
be able to discard changes before automatic posting occurs.
  Unfortunately, using the Abort procedure in a BeforePost
event not only stops the posting but also stops whatever the user was
trying
to do (ie moving to the next record)
Thanks,
  Jake Waxman

 

Re:Defeating Automatic Posting


Quote
Jakewaxman wrote:

> Howdy,
>   Has anyone discovered a way to turn off the automatic posting on
> record movements?  I'd like to have things set up so that posting occurs
> only when the user explicitly asks for it.  At the very least I'd like the
> user to
> be able to discard changes before automatic posting occurs.
>   Unfortunately, using the Abort procedure in a BeforePost
> event not only stops the posting but also stops whatever the user was
> trying
> to do (ie moving to the next record)
> Thanks,

I'm not sure if I understand what kind of behaviour you exactly want.
When you move to another record, the only possible methods for changed
data is to Post it or Cancel. Is it that you want to move to next
record, and instead of Posting the changes to current record, you
want to Cancel them?

What ever button or method you use to move to Table.Prior/Next, couldn't
simple
 if Table.State in [dsEdit,dsInsert] then Table.Cancel;
before these events do the job?

Re:Defeating Automatic Posting


Jake,

You are looking for CachedUpdates.  If you are using D2 or later, change
the value of the CachedUpdates property of your Dataset to true...  That's
all.  Just remember to let the user apply updates at some time.

You can also loop through the cache, restoring edits, deleting insert and
undeleting deleted records!

In D1, I have created temporary tables, posting modifications to them, and
using BatchMove when the user actually wants to post.  Hopefully you are
not in D1, and you won't have to go through this.

Ken
--------------------------------------
Notice at no time do my fingers leave my hands...
Quality training touches your technical side and helps you grow.
--------------------------------------
Master Certified Delphi 3 Instructor
Master Certified C++Builder Instructor
http://www.knowledgeable.com
k...@knowledgeable.com
+

Jakewaxman <jakewax...@aol.com> wrote in article
<19970601204801.QAA12...@ladder02.news.aol.com>...

Quote
> Howdy,
>   Has anyone discovered a way to turn off the automatic posting on
> record movements?  I'd like to have things set up so that posting occurs
> only when the user explicitly asks for it.  At the very least I'd like
the
> user to
> be able to discard changes before automatic posting occurs.
>   Unfortunately, using the Abort procedure in a BeforePost
> event not only stops the posting but also stops whatever the user was
> trying
> to do (ie moving to the next record)
> Thanks,
>   Jake Waxman

Re:Defeating Automatic Posting


Thanks for your replies.

Unfortunately I am in D1 and don't have access to cached updates. The
machines
I'm running on aren't ready for WIN95 yet.

There are a number of problems with the simple solution of issuing a
cancel when the user clicks on a next or prior button
1) The Navigator ctrl becomes useless
2) There are lots of other ways to move off the current record
    ie Insert, FindKey, Clicking on another row a DBGrid, and
   probably others.  One would need to track them all down and put
   the Cancel in each spot. Seems to me there ought to be one spot
  in the TTable object that all these other methods call right before
issuing
the Post command where a strategically placed Cancel will take care of
everything. But Where??

Thanks,
  Jake

Re:Defeating Automatic Posting


Quote
Jakewaxman wrote:
>   Has anyone discovered a way to turn off the automatic posting on
> record movements?  I'd like to have things set up so that posting occurs

.> only when the user explicitly asks for it.  At the very least I'd
like the.
.> user to
.> be able to discard changes before automatic posting occurs.
.>   Unfortunately, using the Abort procedure in a BeforePost
.> event not only stops the posting but also stops whatever the user was
.> trying
.> to do (ie moving to the next record)
.> Thanks,
.>   Jake Waxman

I haven't found this with beforepost

I actually check with the user whether they want to discard changes (in
which case I cancel).  If they don't, I abort.  If you want to annoy
your users, just cancel anyway.

Andrew

Re:Defeating Automatic Posting


Quote
Jakewaxman wrote:

> Thanks for your replies.

> Unfortunately I am in D1 and don't have access to cached updates. The
> machines
> I'm running on aren't ready for WIN95 yet.

> There are a number of problems with the simple solution of issuing a
> cancel when the user clicks on a next or prior button
> 1) The Navigator ctrl becomes useless
> 2) There are lots of other ways to move off the current record
>     ie Insert, FindKey, Clicking on another row a DBGrid, and
>    probably others.  One would need to track them all down and put
>    the Cancel in each spot. Seems to me there ought to be one spot
>   in the TTable object that all these other methods call right before
> issuing
> the Post command where a strategically placed Cancel will take care of
> everything. But Where??

> Thanks,
>   Jake

How about using Try/Finally to prevent total exit from the program block
after Abort?
I have used this succesfully in some cases.

    try
      Abort;          {11.6.96 This aborts the actual DeleteRecord }
    finally          
      Orders.Post;    {this ensures that we'll still be able to Post Orders}
      dbiSaveChanges(Orders.Handle);  {Flush the buffer}
    end;

Re:Defeating Automatic Posting


On 2 Jun 1997 16:11:19 GMT, jakewax...@aol.com (Jakewaxman) wrote:

Quote
>There are a number of problems with the simple solution of issuing a
>cancel when the user clicks on a next or prior button
>1) The Navigator ctrl becomes useless
>2) There are lots of other ways to move off the current record
>    ie Insert, FindKey, Clicking on another row a DBGrid, and
>   probably others.  One would need to track them all down and put
>   the Cancel in each spot. Seems to me there ought to be one spot
>  in the TTable object that all these other methods call right before
>issuing
>the Post command where a strategically placed Cancel will take care of
>everything. But Where??

I missed your original post, but I think I get the idea.  Am I correct
that you are trying to prevent any POST except when you explicitly
issue one?  If so..

No, there's no propery or method to achive this goal, but you could
create your own TTable object, inherite from the TTable, and override
the CheckBrowseMode method of the TTable.  The CheckBrowseMode is
where the automatic post is performed....

Here's the code  (copyright Borland).
----------------------------------------------------------------
procedure TDataSet.CheckBrowseMode;
begin
  if State = dsInactive then DBError(SDataSetClosed);
  DataEvent(deCheckBrowseMode, 0);
  case State of
    dsEdit, dsInsert:          
      begin
        UpdateRecord;    
        if Modified then
           Post                            <<<----- there it is!
        else Cancel;
      end;
    dsSetKey:
      Post;
  end;
end;
------------------------------------------------------
TTable inherits this method from TDataSet.  You can just override it
in your new TTable object.  I would add a property to the table,
called AutomaticPost.  If it's true, let the Post occur.  If it's
false, issue a cancel instead.

Let me know if you need some pointers or examples.  I have a modified
TTable component around here somewhere...

Chuck Gadd
Director of Software Development, {*word*104} FX Communications.
e-mail:cgadd-NOS...@{*word*104}-fx.com  http://www.{*word*104}-fx.com
Remove the -NOSPAM from my email address to send me e-mail.
*** I boycott businesses that send me unsolicited email adverti{*word*224}ts ***

Re:Defeating Automatic Posting


On Mon, 02 Jun 1997 23:26:45 +0930, Andrew Gabb <ag...@tpgi.com.au>
wrote:

Quote
>I haven't found this with beforepost

>I actually check with the user whether they want to discard changes (in
>which case I cancel).  If they don't, I abort.  If you want to annoy
>your users, just cancel anyway.

But if you just do a cancel, won't that also Cancel any POST commands
that you issue?

Chuck Gadd
Director of Software Development, {*word*104} FX Communications.
e-mail:cgadd-NOS...@{*word*104}-fx.com  http://www.{*word*104}-fx.com
Remove the -NOSPAM from my email address to send me e-mail.
*** I boycott businesses that send me unsolicited email adverti{*word*224}ts ***

Re:Defeating Automatic Posting


Thanks to all who tried to help.
I happened to find the Delphi RAD pack on sale for $30
at Software etc
It contains the VCL source which shows that autoposting
behavior is completely controlled by a single line
in a virtual procedure in TDataSet -- CheckBrowseMode

By changing the line I'm able to switch to manual or
user confirmed posting without resorting to raising exceptions
or tracking down every way the user may have to move between records.
I'm not sure its legal for me to post the code since its a
modification of Borland's code but I'm happy to share the solution
with anyone who requires it in the future.

Thanks again,
Jake

Other Threads