![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 11 to 19 of 19 total |
![]() |
Sat, Dec 20 2014 2:28 PM | Permanent Link |
TD Advanced Data Systems, Inc. | Raul wrote:
On 12/20/2014 10:24 AM, TD wrote: > Uli, Walter thank you so much for helping! I have searched the EWB manual and this forum for information on the OnCommit event and have found nothing. Can you guys give me an example as to how to use / work with this event? I don't believe there is a OnCommit event - i assume what they meant was that you call "Commit" and then wait for either AfterCommit or OnCommitError events. I suggest you review the datasets section : http://www.elevatesoft.com/manual?action=topics&id=ewb1§ion=using_datasets It really does cover all the details on how this works. Start with DataSet Architecture and at least read Transactions (though i'd suggest you read them all). For example you need to be aware of the TransactionLevel : only if it reaches 0 does the data get posted to back end server, etc. Raul Any chance someone could post a code example of how to use AfterCommit to tell when the data has actually been written to the database? TD |
Sat, Dec 20 2014 3:09 PM | Permanent Link |
Walter Matte Tactical Business Corporation | Yes I gave you the wrong event names: if Database.InTransaction then begin Database.AfterCommit := AfterCommit; Database.OnCommitError := OnCommitError; Database.Commit; end; I attached a full example on Dec 1 in this thread ...... Walter |
Sat, Dec 20 2014 3:27 PM | Permanent Link |
TD Advanced Data Systems, Inc. | Walter Matte wrote:
Yes I gave you the wrong event names: if Database.InTransaction then begin Database.AfterCommit := AfterCommit; Database.OnCommitError := OnCommitError; Database.Commit; end; I attached a full example on Dec 1 in this thread ...... Walter Thank you Walter. I will take a look again at your example. TD |
Sat, Dec 20 2014 5:19 PM | Permanent Link |
Raul Globestar Systems ![]() | On 12/20/2014 2:28 PM, TD wrote:
> Any chance someone could post a code example of how to use AfterCommit to tell when the data has actually been written to the database? TD, AfterCommit simply means that the database operation has completed on the server - that's all there is to it. Due to the asynchronous nature of javascript this the only way of letting you know of this - due to the network connection etc this could be seconds in the future. How your app reacts is unique to each application - for example if you have a Save button that commits the transaction then upon receiving AfterCommit you can disable or hide the button; or maybe you had a window up telling user to wait so now you can hide the window and move on. The longer explanation goes like this: - TDataSet DOES NOT directly represent dbisam/edb or any other back end database you are using. - TDataset represents a "local" copy of data that was downloaded from server in JSON format and loaded into TDataset. - Any editing/inserts/deletes only modify the local data and not the actual back-end database. - If you do wish to modify the actual back-end database you must use transactions. Specifically once you call StartTransaction all the changes you make to tdataset will be logged (note again that this is all logged locally at this point still). - when you call Commit the TDataBase takes all these changes, and starts a new TServerRequest (basically a web POST request to the back-end web server) and waits for the RequestComplete event. - Assuming your connection to the server works at some point in the future RequestComplete is fired which in turn causes the TDataBase to call AfterCommit event. Raul |
Tue, Dec 23 2014 11:18 AM | Permanent Link |
TD Advanced Data Systems, Inc. | Uli, Walter, and Raul thank you for your patience and time with this. I finally got it to work! It turns out I had errors in the way I was coding the params for the datasets.
I have read through the manual regarding Datasets and I have tried to follow the code example that Walter attached to a post earlier in this thread. Below is the final code that works, would you guys please look it over to see if I have got it correct? Would be grateful if you would! I also attached a screen capture showing Form6. Thanks TD <code> unit Unit6; interface uses WebCore, WebForms, WebCtrls, WebData; type TForm6 = class(TForm) Label1: TLabel; Label2: TLabel; Edit2: TEdit; Label3: TLabel; Edit3: TEdit; Edit4: TEdit; btnSave: TButton; ComboBox1: TComboBox; Label5: TLabel; ds6: TDataSet; ds6B: TDataSet; procedure btnSaveClick(Sender: TObject); procedure Form6Show(Sender: TObject); procedure ds6AfterLoad(Sender: TObject); procedure Form6Close(Sender: TObject); procedure ds6BAfterLoad(Sender: TObject); procedure ds6AfterSave(Sender: TObject); private { Private declarations } procedure AfterCommit(Sender: TObject); procedure OnCommitError(Sender: TObject; const ErrorMsg : string); public { Public declarations } dblRandom: double; //public field strRandom: string; //public field intRandom: integer; //public field end; var Form6: TForm6; implementation uses unit1, unit7; procedure TForm6.btnSaveClick(Sender: TObject); begin Form6.dblRandom := Random; Form6.strRandom := DoubleToStr(dblRandom); Form6.strRandom := strReplace(strRandom,'0.','',True, True); Form6.intRandom := strToInt(strRandom); Form6.ds6.columns['random_number'].AsInteger := Form6.intRandom; Form6.ds6.Save; end; procedure TForm6.Form6Show(Sender: TObject); begin Database.Load(ds6); end; procedure TForm6.ds6AfterLoad(Sender: TObject); begin Database.StartTransaction; Form6.ds6.Insert; end; procedure TForm6.Form6Close(Sender: TObject); begin Form7.ShowModal; end; procedure TForm6.ds6BAfterLoad(Sender: TObject); begin Form1.LoadDateRange(false); Form1.intPID := ds6B.columns['pid'].AsInteger; Form6.Close; end; procedure TForm6.AfterCommit(Sender: TObject); begin Database.AfterCommit := nil; Database.OnCommitError := nil; //find pid of record just saved Form6.ds6B.params.clear; Form6.ds6B.params.add('intRandom='+IntToStr(Form6.intRandom)+''); Database.Load(ds6B); end; procedure TForm6.OnCommitError(Sender: TObject; const ErrorMsg : string); begin Database.AfterCommit := nil; Database.OnCommitError := nil; ShowMessage('Error: ' + ErrorMsg); end; procedure TForm6.ds6AfterSave(Sender: TObject); begin if Database.InTransaction then try Database.AfterCommit := AfterCommit; Database.OnCommitError := OnCommitError; Database.Commit; except Database.Rollback; raise; end; end; end. </code> Attachments: Form6.JPG |
Sun, Dec 28 2014 7:56 PM | Permanent Link |
TD Advanced Data Systems, Inc. | Anyone?
Thanks, TD |
Mon, Dec 29 2014 10:58 AM | Permanent Link |
TD Advanced Data Systems, Inc. | Perhaps I ask too much. I really would like to understand this line of code from the master/detail example:
Database.AfterCommit:=AfterCommit; What is the "Aftercommit" on the right side of the equals sign? master/deatil example code: procedure TOrderEntryDlg.SetupOrder(OrdersDataSet: TDataSet; IsInserting: Boolean=False); begin Inserting:=IsInserting; CancelChecked:=False; CommitStarted:=False; RollbackStarted:=False; Database.BeforeCommit:=BeforeCommit; Database.OnCommitError:=CommitError; Database.AfterCommit:=AfterCommit; Database.BeforeRollback:=BeforeRollback; Database.OnRollbackError:=RollbackError; Database.AfterRollback:=AfterRollback; Orders:=OrdersDataSet; OrderIDLabel.DataSet:=Orders; OrderDateLabel.DataSet:=Orders; PONumberEdit.DataSet:=Orders; TermsComboBox.DataSet:=Orders; OrderTotalLabel.DataSet:=Orders; AmountPaidEdit.DataSet:=Orders; BalanceDueLabel.DataSet:=Orders; SpecialInstructionsMemo.DataSet:=Orders; PurchaseTotalLabel.DataSet:=Orders; ShippingTotalLabel.DataSet:=Orders; CustomerItems.Params.Clear; CustomerItems.Params.Add('OrderID='''+Orders.Columns['OrderID'].AsString+''''); Database.Load(CustomerItems); Thanks, TD |
Mon, Dec 29 2014 11:41 AM | Permanent Link |
Walter Matte Tactical Business Corporation | TD wrote:
Perhaps I ask too much. I really would like to understand this line of code from the master/detail example: Database.AfterCommit:=AfterCommit; What is the "Aftercommit" on the right side of the equals sign? See orderentry form - declared in Private section: procedure AfterCommit(Sender: TObject); procedure TOrderEntryDlg.AfterCommit(Sender: TObject); begin Close; end; Walter |
Mon, Dec 29 2014 11:50 AM | Permanent Link |
Raul Globestar Systems ![]() | On 12/29/2014 10:58 AM, TD wrote:
> Perhaps I ask too much. I really would like to understand this line of code from the master/detail example: Christmas week is slow anyways and without full project people would need to create a project and paste your code and make it work so ... > Database.AfterCommit:=AfterCommit; > What is the "Aftercommit" on the right side of the equals sign? It's a function you defined that you wish to get called by built-in database object for AfterCommit event. It has to be defined as per docs : http://www.elevatesoft.com/manual?action=viewevent&id=ewb1&comp=TDatabase&event=AfterCommit Basically just a function with Sender:TObject as only argument. It's the same thing as any event (control OnChange, form OnShow, etc) except you're assigning it in code (as there is no IDE component for EWB default Database object). Better example might be not not use same name so if you defined a procedure like this : procedure TOrderEntryDlg.MyCustomAfterCommit(Sender: TObject); begin //do whatever it needs to do in AfterCOmmit end; and then the code when setting this up would be Database.AfterCommit:=MyCustomAfterCommit; Raul |
« Previous Page | Page 2 of 2 | |
Jump to Page: 1 2 |
This web page was last updated on Monday, September 25, 2023 at 03:00 PM | Privacy Policy![]() © 2023 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |