看看下面的代码,也许对你有帮助· 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.CopyDataClick(Sender: TObject);var SavePlace: TBook; PrevValue: Variant; begin with Table1 do begin { get a book so that we can return to the same record } SavePlace := GetBook; { move to prior record} FindPrior; { get the value } PrevValue := Fields[0].Value; {Move back to the book this may not be the next record anymore if something else is changing the dataset asynchronously } GotoBook(SavePlace); { Set the value } Fields[0].Value := PrevValue; { Free the book } FreeBook(SavePlace); 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.procedure TForm1.Table1DataChange(Sender: TObject; Field: TField);begin if Table1.BOF then CopyData.Enabled := False else CopyData.Enabled := True; end;
是的,如下:var SavePlace: TBook;//要定义一个用于保存这个点的变量 PrevValue: Variant; begin withClientDataSet1 do begin SavePlace := GetBook; try ....................... GotoBook(SavePlace);//回到原来的记录 finally FreeBook(SavePlace);//释放这个变量 end; end;
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.CopyDataClick(Sender: TObject);var
SavePlace: TBook;
PrevValue: Variant;
begin
with Table1 do
begin
{ get a book so that we can return to the same record }
SavePlace := GetBook; { move to prior record} FindPrior; { get the value } PrevValue := Fields[0].Value; {Move back to the book this may not be the next record anymore
if something else is changing the dataset asynchronously }
GotoBook(SavePlace);
{ Set the value }
Fields[0].Value := PrevValue;
{ Free the book }
FreeBook(SavePlace);
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.procedure TForm1.Table1DataChange(Sender: TObject; Field: TField);begin
if Table1.BOF then
CopyData.Enabled := False
else
CopyData.Enabled := True;
end;
SavePlace: TBook;//要定义一个用于保存这个点的变量
PrevValue: Variant;
begin
withClientDataSet1 do
begin
SavePlace := GetBook;
try
.......................
GotoBook(SavePlace);//回到原来的记录
finally
FreeBook(SavePlace);//释放这个变量
end;
end;