Board index » delphi » Paradox Autoincrement Fields Cause Key Violation -- Help!

Paradox Autoincrement Fields Cause Key Violation -- Help!

I have been trying to use Paradox autoincrement fields in a Delphi
application that I am developing.  The tables in question need a unique
number to serve as a key, and the number itself is not of any importance
to the end users of the application.  Autoincrement fields seem to be just
the answer.  I created by tables with the database desktop, made the first
field an autoincrement field, and flagged it as the key field.  All well
and good.

However, whenever I try to add anything to the table using a Delphi form,
I get a key violation whenever I try to post the edit.  There are no
records in the table.

I changed the field type to long integer, added a field for the key to my
Delphi form so the user could enter the number, and it works just fine.

I must be missing something, but there seems to be almost nothing about
using autoincrement fields in the printed documentation, the online
Acrobat documentation, the Windows Help files, or in "Delphi Programmming
Explorer," "Delphi Unleashed," or "Delphi Developer's Guide."

Can anyone help me out here?  I'd be especially interested in help from
Borland.  Thanks.

--Jim Tubman

----------------------------------------------------------------------------
James B. Tubman                       Alberta Research Council
Program Leader                        Advanced Computing & Engineering Dept.
jbtub...@skyler.arc.ab.ca             3rd Floor
http://www.arc.ab.ca/                 6815 - 8 Street NE
Phone: (403) 297-2656                 Calgary, Alberta
Fax:   (403) 297-2339                 Canada T2E 7H7
http://akaela.arc.ab.ca/WWW/jbtpgp.html  -- PGP Public Key
----------------------------------------------------------------------------
     "Me Transmitte Sursum Caledoni! Sub Hoc Non Vita Inteligens Est!"
                                       -Iacobus Tiberius Ecclessia
----------------------------------------------------------------------------

 

Re:Paradox Autoincrement Fields Cause Key Violation -- Help!


Quote
tub...@arc.ab.ca (Jim Tubman) wrote:
>I have been trying to use Paradox autoincrement fields in a Delphi
>application that I am developing.  The tables in question need a unique
>number to serve as a key, and the number itself is not of any importance
>to the end users of the application.  Autoincrement fields seem to be just
>the answer.  I created by tables with the database desktop, made the first
>field an autoincrement field, and flagged it as the key field.  All well
>and good.
>However, whenever I try to add anything to the table using a Delphi form,
>I get a key violation whenever I try to post the edit.  There are no
>records in the table.
>I changed the field type to long integer, added a field for the key to my
>Delphi form so the user could enter the number, and it works just fine.
>I must be missing something, but there seems to be almost nothing about
>using autoincrement fields in the printed documentation, the online
>Acrobat documentation, the Windows Help files, or in "Delphi Programmming
>Explorer," "Delphi Unleashed," or "Delphi Developer's Guide."

When you say (and rightly so) that the auto-increment field is of no
concern to the end-user, how did you implement that? You did not make the
auto-increment field read-only or invisible (at the TField level) did you?

How, exactly, were you adding and posting records? Were you relying on the
automated process by calling the Append or Insert methods of the TTable? Or
using non-data-aware components (like the TEdit, TMaskEdit, and TMemo),
filling field values programmatically, and then calling the Post method?

Are you using a TDBGrid for the editing? In such a case, I would usually
make the auto-increment field invisible at the TDBGrid level. This would be
done by addressing the auto-increment field via the Fields property of the
TDBGrid, setting its Visible property to False:

  DBGrid1.Fields[0].Visible := False;

If you use a new, dummy project and add a simple TDBGrid to the form and
try to add records, can you do so? This would eliminate other factors
exclusive to your original application as circumstances that might
interfere with the process.

**************************************************************************
Steve Koterski
Local InterBase Server Technical Support
Borland International, Inc.

Re:Paradox Autoincrement Fields Cause Key Violation -- Help!


In <tubman-2609951043060...@akaela.arc.ab.ca>, tub...@arc.ab.ca (Jim Tubman) writes:

Quote
>However, whenever I try to add anything to the table using a Delphi form,
>I get a key violation whenever I try to post the edit.  

        Have you made the auto-increment field a required field?  You can't
do that, or the program gets caught in a loop.  This has been a "problem" with
Paradox (for Windows, at least) for years.

Steve

Other Threads