Board index » delphi » Automatic Post, I hate it ...

Automatic Post, I hate it ...

Hi!

In a data-entry-dialog I don't want that the BDE posts the changes automaticly
to the table. I want to have a button "OK" to post the data und a button
"Cancel" to throw the changes away.

How can I do this with Delphi 2.0 und Paradox-Tables ?

I tried the transaction management with StartTransaction at "CreateForm",
Transmit at "OK" and Rollback at "Cancel", but it doesn't work.
And I think this is not the perfect way ....

Bye,
  Georg.

 

Re:Automatic Post, I hate it ...


Quote
Georg Ledermann wrote:

> Hi!

> In a data-entry-dialog I don't want that the BDE posts the changes automaticly
> to the table. I want to have a button "OK" to post the data und a button
> "Cancel" to throw the changes away.

> How can I do this with Delphi 2.0 und Paradox-Tables ?

> I tried the transaction management with StartTransaction at "CreateForm",
> Transmit at "OK" and Rollback at "Cancel", but it doesn't work.
> And I think this is not the perfect way ....

> Bye,
>   Georg.

  What about making the controls that users edit to be non-data-aware?
When you click on "OK", read the text from the controls, verify the
entry and write them explicitly to the underlying table?  You have to handle
re-synching data with the table yourself.

  I have struggled with similar data-entry problems myself.  Another
choice is to make a copy of the target table, and associate it with the
data controls.  When you click OK you copy the record from the temp
table to the "real" table.  (This leads to a big mess. You really want
to allow only 1 record in the temp table)

--
Paul Schopf                           mailto://sch...@gsfc.nasa.gov
Coupled Climate Dynamics Group/971    http://ccdg.gsfc.nasa.gov/~paul
NASA Goddard Space Flight Center              
Greenbelt, MD 20771

Re:Automatic Post, I hate it ...


Quote
g...@beavis.infox.com (Georg Ledermann) wrote:
>Hi!
>In a data-entry-dialog I don't want that the BDE posts the changes automaticly
>to the table. I want to have a button "OK" to post the data und a button
>"Cancel" to throw the changes away.
>How can I do this with Delphi 2.0 und Paradox-Tables ?
>I tried the transaction management with StartTransaction at "CreateForm",
>Transmit at "OK" and Rollback at "Cancel", but it doesn't work.
>And I think this is not the perfect way ....
>Bye,
>  Georg.

The way I got it to work was as follows:

dbTable1.append;   {(or .edit whichever}
if frmNewPublication.showmodal then
    dbTable1.post;
else
   dbTable1.cancel;

----
Note the dialog box is modal.  I have all the fields on the dialog
linked to the database, i.e. dbedits, etc. So when we get back
from the dialog, we can do the post.

On the dialog use the default speed buttons OK and CANCEL
to set up the dialog's return modal results to mrOK and mrCancel
respectively.

Hope this helps
Iceman      

Re:Automatic Post, I hate it ...


Quote
>   g...@beavis.infox.com (Georg Ledermann) writes:
>  Hi!

>  In a data-entry-dialog I don't want that the BDE posts the changes automaticly
>  to the table. I want to have a button "OK" to post the data und a button
>  "Cancel" to throw the changes away.

>  How can I do this with Delphi 2.0 und Paradox-Tables ?

>  I tried the transaction management with StartTransaction at "CreateForm",
>  Transmit at "OK" and Rollback at "Cancel", but it doesn't work.
>  And I think this is not the perfect way ....

>  Bye,
>    Georg.

In Delphi 1.0 I put a MessageDlg in the BeforePost event handler of the TQuery or TTable that your making changes to.
eg

if MessageDlg( 'Update this record?', mtConfirmation, [mbYes,mbNo,mbCancel], 0) <> mrYes then
     cancel;

cancel will return the fields to ther previous values.

Hope this helps

David Arnall.

Re:Automatic Post, I hate it ...


Quote
dav...@acay.com.au wrote:

> >   g...@beavis.infox.com (Georg Ledermann) writes:
> > I want to have a button "OK" to post the data und a button
> >  "Cancel" to throw the changes away.If the user click on cancelbutton,  call your table's 'Cancel' method.  

Otherwise if user press OK, then call your table's Post method. Before
you call Post or Cancel, check if your table is in dsBrowse,
dsInsert,dsEdit, ... otherwise you'll get a 'Table not in Edit mode' or
something.

Quote
> In Delphi 1.0 I put a MessageDlg in the BeforePost event handler of the TQuery or TTable that your making changes to.
> eg

> if MessageDlg( 'Update this record?', mtConfirmation, [mbYes,mbNo,mbCancel], 0) <> mrYes then
>      cancel;

Bad programming practice !!!  
If the users presses 'OK' then he want to save it, so why for God's sake
do want to ask him thereafter if he want to update.   If he press OK,
just save it, if he press Cancel, throw away the changes.

Sorry no offence to you in particulary David. ;-)

A lot programmers make these mistakes again, and again, (included me,
and even Microsoft) just annoying the user with these redundant
questions.
This is an example of an easy programming solution : easy for the
programmer, but annoying the user again and again.

Hope I helped,
Pascal,
Ingelmunster,
Belgium

Re:Automatic Post, I hate it ...


Quote
> In a data-entry-dialog I don't want that the BDE posts the changes automaticly
> to the table. I want to have a button "OK" to post the data und a button
> "Cancel" to throw the changes away.

> How can I do this with Delphi 2.0 und Paradox-Tables ?

> I tried the transaction management with StartTransaction at "CreateForm",
> Transmit at "OK" and Rollback at "Cancel", but it doesn't work.
> And I think this is not the perfect way ....

Delphi 2.0 introduced 'Cached Updates'.  There's an entire chapter on
it in the Database Applications manual.  (At least, there is in the
English documentation set.  I have no idea what kind of manuals they
give ship in German.)

I presume that you're using a DBGRID, since there is no 'automatic post'
for normal data-aware components.

Hope this helps.

--
Glenn Chambers
gcham...@bright.net
Toledo, OH

Re:Automatic Post, I hate it ...


Quote
In article <4mgque$...@lei.acay.com.au>, dav...@acay.com.au wrote:
>In Delphi 1.0 I put a MessageDlg in the BeforePost event handler of the TQuery or TTable that your making changes to.
>eg

>if MessageDlg( 'Update this record?', mtConfirmation, [mbYes,mbNo,mbCancel], 0) <> mrYes then
>     cancel;

>cancel will return the fields to ther previous values.

What database backend are you using? Paradox?

I had similar code in an app accessing an interbase query, and it raised
an exception when I cancelled the post in the BeforePost event. :-(

--
=\
 *=- R.Moberg, CD-Player Pro info @ http://www.sn.no/~mobergru/
=/

Re:Automatic Post, I hate it ...


Hi!

Thank you for the several mails answering to my question!

I'm using now the following method. It works pretty good.

------------------------------

(The form has two buttons: "Cancel" and "OK".
 The form has one table: "Table")

PROCEDURE ButtonOKClick (Sender : TObject);
  BEGIN
    IF Table.state IN [dsEdit, dsInsert] THEN
     BEGIN
       Table.Tag := 1; { user wants saving explicit }
       Table.Post;
     END;
    Close;
  END;

PROCEDURE ButtonCancelClick (Sender : TObject);
  VAR
    CanClose : BOOLEAN;
  BEGIN
    CanClose := TRUE;
    IF Table.state IN [dsEdit, dsInsert] THEN
     FormCloseQuery (Sender, CanClose);
    IF CanClose THEN
     Close;
  END;

PROCEDURE FormCloseQuery (Sender : Tobject; VAR CanClose : BOOLEAN);
  BEGIN
    inherited;
    IF Table.state IN [dsEdit, dsInsert] THEN
     CASE MessageDlg ('Save changes?', mtWarning, [mbYes,mbNo,mbCancel], 0) OF
      mrYes    : BEGIN
                   Table.Tag := 1;
                   Table.Post;
                   CanClose := TRUE;
                 END;
      mrNo     : BEGIN
                   Table.Cancel;
                   CanClose := TRUE;
                 END;
      mrCancel : CanClose := FALSE;
     END;
  END;

......

PROCEDURE TableBeforePost (DataSet : TdataSet);
  BEGIN
    IF Table.Tag = 0 THEN { User has NOT pressed the save-button }
     CASE MessageDlg ('Save changes?', mtWarning, [mbYes,mbNo,mbCancel], 0) OF
       mrNo     : BEGIN
                    Table.Cancel;
                    Abort;
                  END;
       mrCancel : Abort;
     END
    ELSE
     Table.Tag := 0;
  END;

-----------------------------------------

That's all.

Bye,
  Georg.

Other Threads