TDBGrid for Delphi 1

When using a TDBGrid, with Delphi 1, how can you stop it creating a new record, when the user hits the tab key on the last record displayed.
Who is Participating?
millerwConnect With a Mentor Commented:
Nick--try this set of code-------

procedure TdmdStrategyYear.BeforeInsert(DataSet: TDataSet);
//Used only on tabs 1 and 2 (zero based) of Setup.  Prevents user from adding
//an account to the files.

That is the BeforeInsert event that I use in a program to accomplish the task.  Call the Table's Cancel event to tell the table to stop processing the insert.  Then use the Abort--defined in the SysUtils unit--to tell the TDbGrid to abort the keystroke.  That fixes it up nicely.  Can't remember WHY both calls are needed, but I remember it ran into a problem when I only called one or the other.  Try it if you want, but I'm pretty sure you have to include a call to both.

If you have problems, give me a ring.

BTW, this is D3 code so some of the procedures may not be included for D1, but the Abort should be in one way or another.  One way to fix it--kind of a round about way--is to intercept the Tab key in the KeyDown event of the TDBGrid.  In there just check to see what record you are on.  If you are on the last record and the last column (use SelectedField or SelectedIndex) then just throw out the key (Key:=0).  Word of warning about this-----MAKE SURE TO SET THE FORM THAT CONTAINS THE TDBGRID TO "KEYPREVIEW:=TRUE" SO THAT THE ASSIGNMENT OF KEY:=0 WILL WORK.

I don't remember if D1 has the "abort" procedure.
But in general if you call this one in the BeforeInsert event for the TTable component then it cancels the creation of the new record.

Tell me if D1 has it or not, then I'll be able to check it more occurately.

Hope it helps,
Abort is to stop the printer from printing.
Instead you've to use the Cancel method.
Like Matvey says, in the beforeinsert event you put Table1.Cancel. (Opposite of Table1.Post)

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

No no, I'm sure about this procedure, it just might be only in D3.
Maybe it's a new thing, but in D3 you can abort any procedure that has "Before" event by calling the "abort' proc.

Maybe readonly set true
I think that Abort is only defined in D3. Try to use Cancel.
nichsAuthor Commented:

I just wanted to say thanks for the comments to my question. I haven't had a chance to try them yet. Anyway Thanks!

All Courses

From novice to tech pro — start learning today.