• Delphi Dataset CurValue


    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;

    --------------------- 

  • 相关阅读:
    春色人间
    如是
    Go -- FileManage 自建云盘
    JavaScript -- 定义二维数组
    mysql 碎片清理
    vue2.0项目中使用Ueditor富文本编辑器示例
    浅谈css中一个元素如何在其父元素居中显示
    CSS -- 文字竖直居中
    memcached与redis区别
    mac -- 安装OpenCV
  • 原文地址:https://www.cnblogs.com/jijm123/p/10184298.html
Copyright © 2020-2023  润新知