Subject Re: IB_Grid, pressing enter at last column
Author jeffplata
Thank you, Helen, for your reply.
Please see inline.

> >In the beforepost event of the
> >connected ib_query, i check for some conditions and abort if
> By that, do you mean that you call Sysutils.Abort?

Exactly. Sysutils.Abort;

> Abort is definitely nothing like a Dataset.Cancel. If indeed you
> call Abort, then what happens is that Delphi throws a silent
> exception and redirects execution to the end of the last try ..
> finally block in the execution path. If the form is modal, then of
> course that will close the form. If the form isn't modal, then
> execution will go to the end of the execution path and do the
> Enter key action, e.g. click the Close button or whatever you have.
> If you just want to cancel the editing action and intervene with
> message to the user, call the dataset's Cancel method.

I do not want to Cancel the edit state, just prevent posting so that
the user gets the chance to correct mistakes (And no need to re-enter
the data). This is the general outline of my beforepost event:

if mycondition_is_true then begin
MessageDlg('Row requires this data.',mtWarning,[mbok],0);

while testing I trimmed it down to:

Both code works as intended if I press up or down or click on a
different row, but an exception is thrown if I press Enter at the end
column. (You have already explained this to me). Now if I try to
catch the keypress at the ib_grid's onkeypress event, it appears that
ib_grid was already through with the #13 first hand before my own
onkeypress gets the chance to process the keypress.

> If the current row has any modified fields then pressing the up or
> down key will cause the Post event to fire; but not otherwise. If
> Abort gets called (due to changes in the row) then the BeforePost
> will be visited and your Abort call will happen. However, the
> execution path for an up or down key press is never going to end up
> with closing a form since they are incapable of that. Enter will
> it if there is no trap for it.

So it is by design. I guess I have explained what I really wanted to
do. Can you please give me an idea on how or where to trap the enter
key so that I can prevent it from closing the window?

> Don't know for sure. If you're intervening in the BeforePost in
> order to prevent an invalid entry from making it to the database,
> then you should call Dataset.Cancel and throw an exception that you
> can catch and handle.

No cancel. Thank you.