1 |
<?xml version="1.0" encoding="UTF-8"?> |
2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><!--This file was converted to xhtml by LibreOffice - see http://cgit.freedesktop.org/libreoffice/core/tree/filter/source/xslt for the code.--><head profile="http://dublincore.org/documents/dcmi-terms/"><meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/><title xml:lang="en-US">- no title specified</title><meta name="DCTERMS.title" content="" xml:lang="en-US"/><meta name="DCTERMS.language" content="en-US" scheme="DCTERMS.RFC4646"/><meta name="DCTERMS.source" content="http://xml.openoffice.org/odf2xhtml"/><meta name="DCTERMS.creator" content="Tony Whyman"/><meta name="DCTERMS.issued" content="2015-04-14T13:34:25.280014526" scheme="DCTERMS.W3CDTF"/><meta name="DCTERMS.contributor" content="Tony Whyman"/><meta name="DCTERMS.modified" content="2015-04-14T14:03:55.098407758" scheme="DCTERMS.W3CDTF"/><meta name="DCTERMS.provenance" content="" xml:lang="en-US"/><meta name="DCTERMS.subject" content="," xml:lang="en-US"/><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" hreflang="en"/><link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" hreflang="en"/><link rel="schema.DCTYPE" href="http://purl.org/dc/dcmitype/" hreflang="en"/><link rel="schema.DCAM" href="http://purl.org/dc/dcam/" hreflang="en"/><style type="text/css"> |
3 |
@page { } |
4 |
table { border-collapse:collapse; border-spacing:0; empty-cells:show } |
5 |
td, th { vertical-align:top; font-size:12pt;} |
6 |
h1, h2, h3, h4, h5, h6 { clear:both } |
7 |
ol, ul { margin:0; padding:0;} |
8 |
li { list-style: none; margin:0; padding:0;} |
9 |
<!-- "li span.odfLiEnd" - IE 7 issue--> |
10 |
li span. { clear: both; line-height:0; width:0; height:0; margin:0; padding:0; } |
11 |
span.footnodeNumber { padding-right:1em; } |
12 |
span.annotation_style_by_filter { font-size:95%; font-family:Arial; background-color:#fff000; margin:0; border:0; padding:0; } |
13 |
* { margin:0;} |
14 |
.Heading_20_1 { font-size:130%; margin-bottom:0.0835in; margin-top:0.1665in; font-family:Liberation Sans; writing-mode:page; font-weight:bold; } |
15 |
.P1 { font-size:12pt; font-family:Liberation Serif; writing-mode:page; margin-top:0in; margin-bottom:0.1701in; } |
16 |
.P10 { font-size:12pt; line-height:120%; margin-bottom:0.1in; margin-top:0in; font-family:Liberation Serif; writing-mode:page; } |
17 |
.P11 { font-size:115%; font-weight:bold; margin-bottom:0.0835in; margin-top:0.139in; font-family:Liberation Sans; writing-mode:page; } |
18 |
.P12 { font-size:115%; font-weight:bold; margin-bottom:0.0835in; margin-top:0.139in; font-family:Liberation Sans; writing-mode:page; } |
19 |
.P2 { font-size:12pt; font-family:Liberation Serif; writing-mode:page; margin-top:0in; margin-bottom:0.1701in; } |
20 |
.P3 { font-size:12pt; line-height:120%; margin-bottom:0.0972in; margin-top:0in; font-family:Liberation Serif; writing-mode:page; } |
21 |
.P4 { font-size:12pt; line-height:120%; margin-bottom:0.0972in; margin-top:0in; font-family:Liberation Serif; writing-mode:page; } |
22 |
.P5 { font-size:10pt; line-height:120%; margin-bottom:0.0972in; margin-top:0in; font-family:DejaVu Sans Mono; writing-mode:page; } |
23 |
.P6 { font-size:10pt; line-height:120%; margin-bottom:0.0972in; margin-top:0in; font-family:Liberation Sans; writing-mode:page; } |
24 |
.P7 { font-size:10pt; line-height:120%; margin-bottom:0.1in; margin-top:0in; font-family:Liberation Sans; writing-mode:page; } |
25 |
.P8 { font-size:12pt; line-height:120%; margin-bottom:0.1in; margin-top:0in; font-family:Liberation Serif; writing-mode:page; } |
26 |
.P9 { font-size:12pt; font-family:Liberation Serif; writing-mode:page; margin-top:0in; margin-bottom:0.1701in; } |
27 |
.Bullet_20_Symbols { font-family:OpenSymbol; } |
28 |
.T2 { font-family:DejaVu Sans Mono; font-size:10pt; } |
29 |
<!-- ODF styles with no properties representable as CSS --> |
30 |
.Numbering_20_Symbols .T1 .T3 { } |
31 |
</style></head><body dir="ltr" style="max-width:8.2681in;margin-top:0.7874in; margin-bottom:0.7874in; margin-left:0.7874in; margin-right:0.7874in; writing-mode:lr-tb; "><h1 class="Heading_20_1"><a id="a__Automatic_Posting"><span/></a>Automatic Posting</h1><p class="P1">TDataSet will automatically posted a modified record when scrolling between rows. However, <span class="T1">when the dataset is closed a modified record is “cancelled” and the changes lost. This gives rise to two problems:</span></p><ol><li><p class="P9" style="margin-left:0cm;"><span class="Numbering_20_Symbols" style="display:block;float:left;min-width:0.635cm;">1.</span>In some cases, it may be better to cancel any changes when scrolling rather than post. A good example of this is when using a TDBGrid and you scroll beyond the end of the grid. In this case, a new row is automatically added. If the user ignores this and scrolls back, the append should be cancelled and not saved.<span class="odfLiEnd"/> </p></li><li><p class="P9" style="margin-left:0cm;"><span class="Numbering_20_Symbols" style="display:block;float:left;min-width:0.635cm;">2.</span>Automatic posting on scroll is arguably inconsistent with no similar behaviour on dataset close. Instead, this behaviour has to be added explicitly in an OnBeforeClose event handler.<span class="odfLiEnd"/> </p></li></ol><p class="P2">IBX (v 1.2.3) attempts to improve upon this by adding the “OnValidatePost” event and the “DataSetCloseAction” property.</p><h2 class="P11"><a id="a__The_OnValidatePost_Event"><span/></a>The OnValidatePost Event</h2><p class="P3"><span class="T2">TOnValidatePost = procedure (Sender: TObject; var CancelPost: boolean) of object; </span> </p><p class="P3">This event is called as the first action in the Post method. If it returns with “CancelPost” set to true, then the “Cancel” method is called and the “Post” terminated. The event handler can thus decide if the Post should be cancelled by checking the actual field values, even prompting the user to decide.</p><p class="P3">In terms of event sequencing, the event occurs before an OnBeforePost Event. Thus when the dataset is scrolled and the current record is in the “modified” state, then the following events will occur:</p><ul><li><p class="P10" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>OnValidatePost (returns CancelPost = false)<span class="odfLiEnd"/> </p></li><li><p class="P10" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>OnBeforePost<span class="odfLiEnd"/> </p></li><li><p class="P10" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>OnAfterPost<span class="odfLiEnd"/> </p></li><li><p class="P10" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>OnBeforeScroll<span class="odfLiEnd"/> </p></li><li><p class="P10" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>OnAfterScroll<span class="odfLiEnd"/> </p></li></ul><p class="P3">or </p><ul><li><p class="P10" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>OnValidatePost (returns CancelPost = true)<span class="odfLiEnd"/> </p></li><li><p class="P10" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>OnBeforeCancel<span class="odfLiEnd"/> </p></li><li><p class="P10" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>OnAfterCancel<span class="odfLiEnd"/> </p></li><li><p class="P10" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>OnBeforeScroll<span class="odfLiEnd"/> </p></li><li><p class="P10" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>OnAfterScroll<span class="odfLiEnd"/> </p></li></ul><p class="P8">Note that trying to call “Cancel” in an OnBeforePost handler does not work as the Post still proceeds and, with IBX, an error will be reported.</p><p class="P8">An exception could be raised in <span class="T3">either </span>the OnValidatePost handler or in the OnBeforePost handler to report an actual error in the record.</p><h2 class="P12"><a id="a__The_DataSetCloseAction_Property"><span/></a>The DataSetCloseAction Property</h2><p class="P5">TDataSetCloseAction = (dcDiscardChanges, dcSaveChanges);</p><p class="P4">The property is used in the TIBCustomDataSet.OnBeforeClose method i.e.</p><p class="P7">procedure TIBCustomDataSet.DoBeforeClose;</p><p class="P7">begin</p><p class="P7"> inherited DoBeforeClose;</p><p class="P7"> if State in [dsInsert,dsEdit] then</p><p class="P7"> begin</p><p class="P7"> if FInTransactionEnd and (FCloseAction = TARollback) then</p><p class="P7"> Exit;</p><p class="P7"> </p><p class="P7"> if DataSetCloseAction = dcSaveChanges then</p><p class="P7"> Post;</p><p class="P7"> {Note this can fail with an exception e.g. due to</p><p class="P7"> database validation error. In which case the dataset remains open }</p><p class="P7"> end;</p><p class="P7">end; </p><p class="P4">If the dataset is still in the insert or edit state after any OnBeforeClose handler is called then “Post” is called if the property is set to “dcSaveChanges”. The exception is when the dataset is being automatically closed due to a transaction rollback.</p><p class="P4">If the DataSetClose action is “dcDiscardChanges” (default) then no action occurs and the changes are lost. i.e. the previous behavour.</p><p class="P4">For backwards compatibility reasons, dcSaveChanges must be explicitly set in the Object Inspector.</p><p class="P6"> </p></body></html> |