Subject Re: [firebird-support] After Committed Autoincrement Field Value Not Updated In DBGrid
Author Helen Borrie
At 03:13 13/10/2008, you wrote:
>I'm using Firebird 2.1 and do the coding with Delphi 7.
>
>
>when I insert or append a new record in my form then have the update
>applied and commited, the field Urut value in dbgrid remain empty.
>After I close then reopened the file, the field Urut value is shown
>correctly.
>
>If I don't close and then reopened the file and insert a new record
>in another table which depend on field Urut as foreign key, a error
>occured, said that field Urut has to have a value ?

A Commit ends the transaction but your application is still looking at the database state as it was when the old transaction started. You are getting the effects described because your datasets have not been updated after the Commit. Look for a Refresh method and apply it to all datasets. If Refresh is not supported, then use Close followed by Open.

A tip for when you are using generated keys in Delphi with a master-detail structure is to fetch the generator value in the BeforePost event and write it directly to the new master record. Check whether IBX has a technique for doing this automatically, as the better Delphi components do. For example, IBObjects (which I use) has a GeneratorLinks property where one can associate all generated fields with their generators. It calls an underlying function Gen_ID() that returns the latest generator value; and Gen_ID() can also be called at various levels. If IBX doesn't have such capabilities, it is very simple to write such a function...

However, this list is not a Delphi list. Search the Delphi help for InterBaseXpress (IBX) for some examples. You might find some more IBX help and links at Marco Cantu's website: http://www.marcocantu.com

^ heLen