Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I debugged the code below with Debug DCUs option activated and the weird thing is that SysUtils.ValidateTimeStamp evaluates a TimeStamp with date = 0 to be invalid and therefore throwing a EConvertError exception (instead of return Null or Unassigned).</p> <p>So the end result is that doing an OldValue request to a null field in a dsInsert state is that its invalid. The variant is <strong>NEVER</strong> returned so it is irrelevant if you test it with (field.OldValue &lt;> Null) or VarIsNull(field.OldValue). The exception gets thrown before.</p> <p>The cds_something has two fields (created at design time):</p> <ul> <li>dt_Something </li> <li>num_something</li> </ul> <p>Code:</p> <pre><code>var b: TClientDataset; begin b := cds_somethin; b.Close; b.CreateDataSet; b.Insert; if b.FieldByName('DT_Sometinhg').OldValue &lt;&gt; Null then ShowMessage('Something wrong!!!') else ShowMessage('Normal'); b.Cancel; </code></pre> <p>Note: I messed up with the original editon of this post. This now is the correct interpretation of what I find.</p> <p>Addition: tested with some other field types (string, BCD, Float and Memo) and OldValue is Unassigned - so the test above will evaluate to false.</p> <p>Appear that ONLY TDateField and TDateTimeField show that behavior. TTimeField and TSQLTimeStamp evaluates normal - but TSQLTimeStampField.OldValue does not equal neither to Null or Unassigned (wtf!!)...</p> <p>The snippet changed a little:</p> <pre><code>var b: TClientDataset; begin b := cds_somethin; b.Close; b.CreateDataSet; b.Insert; /* if (b.FieldByName('DT_Something').OldValue &lt;&gt; Null) and (b.FieldByName('DT_Something').OldValue &lt;&gt; Unassigned) then ShowMessage('Something wrong!!!') else ShowMessage('Normal'); */ if (b.FieldByName('ts_Something').OldValue &lt;&gt; Null) and (b.FieldByName('ts_Something').OldValue &lt;&gt; Unassigned) then ShowMessage('Something wrong!!!') else ShowMessage('Normal'); b.Cancel; </code></pre> <p>Where ts_Something is a TSQLTimeStampField. The fields are created at design time.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload