Delphi Learn How Easy It Is To Apply Updates With TFDQuery.OnUpdateRecord In Delphi

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Learn How Easy It Is To Apply Updates With TFDQuery.OnUpdateRecord In Delphi
January 21, 2021 by Konstantin Tomov

The OnUpdateRecord sample shows you how to cache the user changes when using read-only dataset and then, how to apply updates on behalf of queries that cannot post updates directly. To this end, the sample uses the Для просмотра ссылки Войди или Зарегистрируйся event of Для просмотра ссылки Войди или Зарегистрируйся and the Для просмотра ссылки Войди или Зарегистрируйся object.

Location​

You can find the CentralizedCachedUpdates sample project at:
  • Start | Programs | Embarcadero RAD Studio Sydney | Samplesand then navigate to:
    • Object PascalDatabaseFireDACSamplesComp LayerTFDQueryCachedUpdatesOnUpdateRecord
  • Subversion Repositories:
    • You can find Delphi code samples in Для просмотра ссылки Войди или Зарегистрируйся. Search by name into the samples repositories according to your RAD Studio version.

How to Use the Sample​

  1. Navigate to the location given above and open Qry_CachedUpdates.dproj.
  2. Press F9 or choose Run > Run.
1611252121784.png

Files​

File in DelphiContains
Qry_CachedUpdates.dproj
Qry_CachedUpdates.dpr
The project itself.
fCachedUpdates.pas
fCachedUpdates.fmx
The main form.

Implementation​

Before running the sample, the main components are configured at design time using the Для просмотра ссылки Войди или Зарегистрируйся as follows:
SQL:
select p.*, c.CategoryName
from {id Products} p left outer join {id Categories} c on p.CategoryID = c.CategoryID
order by ProductID
Note: In the RDBMS it has one-to-many relation between Categories and Products tables.
SQL:
UPDATE {id Products} SET
  ProductName = :NEW_ProductName,
  SupplierID = :NEW_SupplierID, CategoryID = :NEW_CategoryID,
  QuantityPerUnit = :NEW_QuantityPerUnit, UnitPrice = :NEW_UnitPrice,
  UnitsInStock = :NEW_UnitsInStock, UnitsOnOrder = :NEW_UnitsOnOrder,
  ReorderLevel = :NEW_ReorderLevel, Discontinued = :NEW_Discontinued
WHERE
  ProductID = :OLD_ProductID
SQL:
UPDATE {id Categories} SET
  CategoryName = :NEW_CategoryName
WHERE
  CategoryID = :OLD_CategoryID
  • A Для просмотра ссылки Войди или Зарегистрируйся objects named dsProducts. This component provides an interface between a dataset component and data-aware controls on a form. In this sample, it is used to provide communication between the dataset and the Для просмотра ссылки Войди или Зарегистрируйся where the dataset is displayed. To this end, the following properties are set:
  • The DataSet property of dsProducts is set to qryProducts.
  • The DataSource property of DBGrid1 is set to dsProducts.

For more details, please follow the link to the original post:
Для просмотра ссылки Войди или Зарегистрируйся
Для просмотра ссылки Войди или Зарегистрируйся