加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Delphi Dataset CurValue

发布时间:2020-12-15 09:53:53 所属栏目:大数据 来源:网络整理
导读: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 t

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,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;

?

---------------------?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读