Automatic Key Field Value Generation
When editing dataset it is often convenient not to fill key field(s) values manually but generate them automatically. In the most common way an application developer generates a primary key value basing on a previously created generator. There are three ways to do it.
First, application independent way - developer creates an AFTER INSERT trigger that fills the field value. But there he faces the problem with getting a value inserted by the trigger back to dataset.
Second way is custom key field value generation. A developer can fill a key field value in TCustomIBCQuery.BeforePost event handler. But in that case he should manually execute a query and retrieve the generator value. So this way may be useful only if some special value processing is needed.
Third way, using Generator is the most simple one. A developer only needs to specify two properties - and key field values are generated automatically. There is no need to create a trigger or perform custom BeforePost processing.
... IBCQuery.SQL.Text := 'SELECT DepNo, DepName, Location FROM Department'; IBCQuery.KeyFields := 'DEPT_NO'; // key field IBCQuery.Generator := 'DeptGenerator'; // generator that will generate values ...