• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Delphi Dataset CurValue

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

TField.CurValue Property

 

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

 

 

Description

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.

Description

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).

Description

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:

 

Copy Code

         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.

Description

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: 

 

Copy Code

{

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人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi函数指针(函数可以当参数)发布时间:2022-07-18
下一篇:
如何在Delphi中访问DBF数据库发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap