Delphi Dataset CurValue

TField.CurValue Property

Represents the current value of the field component including changes made by other users of the database

Use CurValue to examine the value of a field when a problem occurs while posting a value to the database using a provider. If the current field value causes a problem, such as a key violation, when posting the value, an event is generated to allow applications to respond to the problem. Provider components generate an OnUpdateError event. If a provider returns problem records to the client dataset, the client dataset generates an OnReconcileError event. In the OnUpdateError or OnReconcileError event handler, NewValue is the unposted value that caused the problem, OldValue is the value that was originally assigned to the field before any edits were made, and CurValue is the value that is currently assigned to the field. CurValue may differ from OldValue if another user changed the value of the field after OldValue was read.

Note: CurValue is only supported when the dataset is a TClientDataSet. In the provider's OnUpdateError event, a temporary client dataset containing fields with a CurValue property is passed to the event handler. 

TField.NewValue Property
Represents the current value of the field component including pending cached updates.

Use NewValue to examine or change the current value of a field when in the process of applying multiple updates. If the current field value is causing a problem, such as a key violation, when applying updates, datasets generate an OnUpdateError event. Similarly, provider components generate an OnUpdateError event when problems occur posting records from a client, and client datasets generate an OnReconcileError event when informed of problems by the provider. In the event handler, assign a new value to NewValue to correct the problem. 

NewValue is the same as Value, except when errors are encountered while posting records. Setting NewValue in an OnUpdateError event handler, an OnUpdateRecord event handler, or an OnReconcileError event handler causes NewValue to differ from Value until the records have finished being applied to the underlying database table.

Note: The NewValue property is only usable when the data is accessed using a TClientDataSet component or cached updates is enabled

TField.OldValue Property
Represents the original value of the field (as a Variant).

Read the OldValue property to examine or retrieve the original value of the field that was obtained from the dataset before any edits were posted. For example, in Delphi the following line replaces current pending changes with a field's original value:

	NewValue :=OldValue;

Once records are applied successfully to the database, the old field value cannot be retrieved.

Note: the OldValue property is only usable when the data is accessed using a TClientDataSet component or cached updates is enabled

TField.Value Property
Represents the data in a field component.

Use Value to read data directly from and write data directly to a field component at runtime. For example, use the Value property to affect the contents of a field that is not Visible.  

Delphi Examples: 

{
This example uses a button to copy the value of a field in
the previous record into the corresponding field in the
current record.
}
procedure TForm1.Button1Click(Sender: TObject);
var
   SavePlace: TBookmark;
   PrevValue: Variant;
begin
   with Customers do
   begin
    { get a bookmark so that we can return to the same record }
    SavePlace := GetBookmark;
    try
      { move to prior record}
      FindPrior; 
      { get the value }
      PrevValue := FindField('Field2').Value;
      {Move back to the bookmark
      this may not be the next record anymore 
      if something else is changing the dataset asynchronously }
      GotoBookmark(SavePlace);
      { Set the value }
      Edit;
      FindField('Field2').Value := PrevValue;
      { Free the bookmark }
    finally
      FreeBookmark(SavePlace);
    end;
  end;
end;

{
To ensure that the button is disabled when there is no
previous record, the OnDataChange event of the DataSource
detects when the user moves to the beginning of file (BOF
property becomes true), and disables the button.  Detection
occurs on scrolling and editing, not selection with the mouse.
} 
procedure TForm1.DS2DataChange(Sender: TObject; Field: TField);
begin
  if Customers.Bof then
    Button1.Enabled := False
  else
    Button1.Enabled := True;
end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值